Swiper滑块错误startAutoplay不是一个函数

时间:2017-12-21 08:30:27

标签: javascript jquery swiper

我遇到了滑键滑块的问题。我希望我的swiper停止鼠标进入并继续mouseleave。但我的控制台显示错误 - > swiper.stopAutoplay不是函数,但会显示控制台日志。和startAutoplay一样。有谁知道我做错了什么?

<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>

2 个答案:

答案 0 :(得分:1)

在版本4.3.5中,您必须使用autoplay.stopautoplay.start。例如:

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

答案 1 :(得分:0)

我正在运行5.1.0。 在console.logging swiper参考之后,我看到每个选项卡都是特定创建的。 因此,在循环中,当我隐藏只需要执行的选项卡时:

swiper[i].autoplay.stop();

然后在标签上点击以显示标签:

swiper[i].autoplay.start();

因此,感谢@nick的上述回答,我得以使它运行起来。