Home Ask Login Register

Developers Planet

Your answer is one click away!

Oliver Watkins February 2016

Disable onSlideChangeEnd listener

I would like to disabled my onSlideChangeEnd callback on my Swiper component.

If a user clicks on the arrows then I want to execute my onSlideChangeEnd callback method, however if I programatically want to slide to a particular image I do not want the onSlideChangeEnd called. Otherwise I get messy listener loop situations.

How do I do this?

I was thinking of having some kind of flag. If this flag is set to false, then the callback code is not executed, like so :

    galleryTop = new Swiper('.gallery-top-product-view', { //'.gallery-top'
        nextButton: '.swiper-button-next',
        prevButton: '.swiper-button-prev',
        spaceBetween: 10,
        onSlideChangeEnd: function (swiper) {


However the callback object seems to reference the old variable value. The 'someFlag' seems to be somewhat random when I use it like this :

    someFlag= true;


    someFlag= false;

Am I missing something fundamental in how I should disable listeners?


Bob Sponge February 2016

According to swiper documentation ( http://www.idangero.us/swiper/api/ ) you can pass third param runCallbacks as false to prevent callbacks execution: galleryTop.slideTo(key, speed, false);

Post Status

Asked in February 2016
Viewed 1,513 times
Voted 4
Answered 1 times


Leave an answer

Quote of the day: live life