I am plugging Slick into a site. I have the home page
working with a slick slide show except for one thing I can not figure out.
I have 2 slides. They progress from a ghosted version of the image
fading in one by one to a full resolution of the image in all its
detail. At that point I want the last image to stop and stay there.
The mark up for the slider is:
<div class="column-right slide">
<div><img src="img/servicios/road.jpg" alt="Road"/></div>
<div><img src="img/sobre_mi/map.jpg" alt="Map"/></div>
</div>
I figured infinite: false would stop it. What actually happens is the
image fades in to full (slides 1-2) and then fades back out to ghosted
(slides 2-1) continuously.
The code to implement is:
$('.slide').slick({
autoplay: true,
autoplaySpeed: 1000,
dots: false,
infinite: false,
speed: 1000,
fade: true,
slide: 'div',
cssEase: 'linear'
});
Am I missing something, misunderstanding something or is this not
possible? Seems any autoplay should have a way to play once (or a
specific number of times)
on('click', function(){ $(slider). slick('slickSetOption', 'autoplay', false, false); });
You can also link to another Pen here (use the . css URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
If you want the slider to stop when it reaches the last slide, you could use a custom method to determine on what slide number the slider is and work your way from there like bellow:
Update
For slick above 1.4 vs:
From the author: In slick 1.4, callback methods have been deprecated and replaced with events
So basically it's the same idea, except a few minor changes:
var item_length = $('.slide > div').length - 1;
var slider = $('.slide').slick({
autoplay: true,
autoplaySpeed: 1000,
dots: false,
infinite: false,
speed: 1000,
fade: true,
slide: 'div',
cssEase: 'linear'
});
// On before slide change
slider.on('afterChange', function(event, slick, currentSlide, nextSlide){
//check the length of total items in .slide container
//if that number is the same with the number of the last slider
//Then pause the slider
if( item_length === slider.slick('slickCurrentSlide') ){
//this should do the same thing -> slider.slickPause();
slider.slickSetOption("autoplay",false,false)
};
});
Check out the demo
For bellow slick 1.4
Note the js used:
var item_length = $('.slide > div').length - 1;
var slider = $('.slide').slick({
autoplay: true,
autoplaySpeed: 1000,
dots: false,
infinite: false,
speed: 1000,
fade: true,
slide: 'div',
cssEase: 'linear',
onAfterChange: function(){
//check the length of total items in .slide container
//if that number is the same with the number of the last slide
//Then pause the slider
if( item_length == slider.slickCurrentSlide() ){
//this should do the same thing -> slider.slickPause();
slider.slickSetOption("autoplay",false,false)
};
}
});
Check out the demo here and hope it helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With