Marcin Mroczko
Marcin Mroczko

Reputation: 143

Swiper slider error startAutoplay is not a function

I got a problem with swiper slider. I would like my swiper stop on mouse enter and continue on mouseleave. But my console shows me an error --> swiper.stopAutoplay is not a function, but the console log is displayed. And the same with startAutoplay. Does anybody know what am I doing wrong?

<script>
    var swiper = new Swiper('.swiper-container', {
      loop: true,
      speed:2000,
      autoplay: {
        delay: 3500,
      },
      pagination: {
        el: '.swiper-pagination',
      },
    });

(function($) {
$('.swiper-container').on('mouseenter', function(e){
    console.log('stop autoplay');
    swiper.stopAutoplay();
  })

  $('.swiper-container').on('mouseleave', function(e){
    console.log('start autoplay');
    swiper.startAutoplay();
  })
})(jQuery);


  </script>

Upvotes: 3

Views: 4868

Answers (2)

asi hej
asi hej

Reputation: 343

I'm running 5.1.0. After console.logging swiper reference i saw that for each tab was specific one created. So in the loop when i was hiding the tabs just needed to:

swiper[i].autoplay.stop();

And on tab click showing the tab:

swiper[i].autoplay.start();

So thanks to answer above by @nick i was able to get this running.

Upvotes: 1

nick
nick

Reputation: 3700

In version 4.3.5 you must use autoplay.stop and autoplay.start. For example:

var mySwiper = new Swiper('.my-swiper');
$('.my-swiper').hover(function() {
    mySwiper.autoplay.stop();
}, function() {
    mySwiper.autoplay.start();
});

Upvotes: 4

Related Questions