The Slick slider is set to autoplay. At the time of play, the slides comes from left to right or first to last. When the slider is reached at the last slide, it starts autoplaying from the last slide to first slide in backward direction.
I want the slider to play from the first slide instead of last when the slider is reached at the last slide.
Initially when the infinite scroll was 'true', everything was working fine. But due the requirement, I had to set the infinite scroll to 'false'. The above problem occurred when the infinite scroll set to 'false'.
When the slider reaches the last slide, I managed to show an alert. What I wanted to do is when the slider reaches the last slide, I wanted to goto first slide instead of showing an alert.
Here is the Fiddle.
$(document).ready(function() {
var slider2 = $('.slider-2').slick({
dots: true,
infinite: false,
autoplay: true,
autoplaySpeed: 1000,
pauseOnFocus: false,
pauseOnHover: false,
pauseOnDotsHover: false,
slidesToShow: 1,
slidesToScroll: 1,
fade: true,
cssEase: 'linear'
});
slider2.on('afterChange', function(event, slick, currentSlide){
// slick - is a slider object with a lot of useful info
// currentSlide - is a current slide index (starts from 0)
if( slick.slideCount === currentSlide + 1 ){
alert('Instead of showing alert goto slide 1.');
}
});
});
<link href="https://kenwheeler.github.io/slick/slick/slick-theme.css" rel="stylesheet"/>
<link href="https://kenwheeler.github.io/slick/slick/slick.css" rel="stylesheet"/>
<link href="https://kenwheeler.github.io/slick/css/prism.css" rel="stylesheet"/>
<link href="https://kenwheeler.github.io/slick/css/style.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="https://kenwheeler.github.io/slick/slick/slick.js"></script>
<style>
.slick-arrow.slick-disabled {
display: none !important;
}
</style>
<section id="features" class="blue">
<div class="content">
<div class="slider slider-2">
<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><h3>7</h3></div>
<div><h3>8</h3></div>
</div>
</div>
</section>
If anyone have a solution/suggestion, please help. Thanks in advance.