Reputation: 295
Using idangerous' Swiper, I've been trying to change options on the fly, in a click event. For instance, I want to stop the auto play after the pagination buttons are clicked.
I've tried things from the API like:
var mySwiper = new Swiper('.index-slider', {
mode: 'horizontal',
paginationClickable: true,
pagination: '.pagination',
autoplay: 2000,
loop: true
});
$('.pagination').on('click',function() {
mySwiper.stopAutoplay();
mySwiper.params.autoplay = 10000
mySwiper.reInit();
});
Multiple variations of that above. I've also tried disabling the loop. The autoplay doesn't slow down, or stop, or anything. If I console.log(mySwiper.params.autoplay); it does indeed show that the value has been updated, it just doesn't do anything ;(
Am I completely off on this? Or can you not change options after initialization?
Upvotes: 1
Views: 13410
Reputation: 9867
Ok, it seems like you do it right. But few things.
So your code should be like:
var mySwiper = new Swiper('.index-slider', {
mode: 'horizontal',
paginationClickable: true,
pagination: '.pagination',
autoplay: 2000,
loop: true
});
$('.pagination').on('click',function() {
mySwiper.stopAutoplay();
mySwiper.params.autoplay = 10000
mySwiper.startAutoplay();
});
Upvotes: 5