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

问题描述 投票:1回答:1

我遇到了滑键滑块的问题。我希望我的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>
javascript jquery swiper
1个回答
1
投票

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

var mySwiper = new Swiper('.my-swiper');
$('.my-swiper').hover(function() {
    mySwiper.autoplay.stop();
}, function() {
    mySwiper.autoplay.start();
});
© www.soinside.com 2019 - 2024. All rights reserved.