Swiper slider 报错 startAutoplay is not a function

Swiper slider error startAutoplay is not a function

我遇到了滑动滑块问题。我希望我的刷卡器在鼠标进入时停止并在鼠标离开时继续。但是我的控制台显示错误 --> 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>

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

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

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

swiper[i].autoplay.stop();

然后在选项卡上单击显示选项卡:

swiper[i].autoplay.start();

感谢@nick 的上述回答,我能够得到这个运行。