Slick - Center Mode (No Partials)
by alexstudioweb
HTML
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.5.9/slick.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.5.9/slick-theme.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.5.9/slick.js"></script>
<div class="slider">
<div>
<h3>1</h3></div>
<div>
<h3>2</h3></div>
<div>
<h3>3</h3></div>
<div>
<h3>4</h3></div>
<div>
<h3>5</h3></div>
<div>
<h3>6</h3></div>
</div>
CSS
h3 {
background: #fff;
color: black;
font-size: 36px;
line-height: 100px;
margin: 10px;
padding: 2%;
position: relative;
text-align: center;
}
JavaScript
$(".slider").slick({
centerMode: true,
focusOnSelect: true,
centerPadding: '60px',
slidesToShow: 3,
dots: true,
responsive: [{
breakpoint: 768,
settings: {
arrows: false,
centerMode: true,
centerPadding: '40px',
slidesToShow: 3
}
}, {
breakpoint: 480,
settings: {
arrows: false,
centerMode: true,
centerPadding: '40px',
slidesToShow: 1
}
}]
});
function setSlideVisibility() {
//Find the visible slides i.e. where aria-hidden="false"
var visibleSlides = $('.slick-slide[aria-hidden="false"]');
//Make sure all of the visible slides have an opacity of 1
$(visibleSlides).each(function() {
$(this).css('opacity', 1);
});
//Set the opacity of the first and last partial slides.
$(visibleSlides).first().prev().css('opacity', 0);
$(visibleSlides).last().next().css('opacity', 0);
}
$(setSlideVisibility());
$('.slider').on('beforeChange', function() {
$('.slick-slide').each(function() {
$(this).css('opacity', 1);
});
});
$('.slider').on('afterChange', function() {
setSlideVisibility();
});