Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
140
rated 0 times [  141] [ 1]  / answers: 1 / hits: 15138  / 7 Years ago, wed, december 20, 2017, 12:00:00

How to stop slider when autoplay activated and reaching end of slide?



currently the slider keep looping to first slide after reaching end slide.



It's using version 4.0.7



HTML



<div class=swiper-container>
<div class=swiper-wrapper>
<div class=swiper-slide>Slide 1</div>
<div class=swiper-slide>Slide 2</div>
<div class=swiper-slide>Slide 3</div>
</div>
<div class=swiper-pagination></div>
<div class=swiper-button-prev></div>
<div class=swiper-button-next></div>
<div class=swiper-scrollbar></div>




Js



var swiper = new Swiper('.swiper-container', {
spaceBetween: 30,
centeredSlides: true,
loop:false,
autoplay: {
delay: 2500,
disableOnInteraction: false,
stopOnLast: true,
},
pagination: {
el: '.swiper-pagination',
clickable: true,
},
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
},
});

More From » jquery

 Answers
23

You can listen to the event slideChange and check your swiper instance for the property isEnd - if true, you set autoplay=false:



swiper.on('slideChange', function(){
if(swiper.isEnd){
swiper.autoplay = false;
}
});


Working fiddle (full example): https://jsfiddle.net/2yhxctxf/






Update: just found an easier way :)



swiper.on('reachEnd', function(){
swiper.autoplay = false;
})


Updated fiddle: https://jsfiddle.net/2yhxctxf/1/






Documentation on the .isEnd property: http://idangero.us/swiper/api/#methods



Documentation on the events: http://idangero.us/swiper/api/#events


[#55630] Monday, December 18, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
eanskylerg

Total Points: 524
Total Questions: 107
Total Answers: 100

Location: Colombia
Member since Mon, May 2, 2022
2 Years ago
;