【问题标题】:Swiper slider error startAutoplay is not a functionSwiper 滑块错误 startAutoplay 不是函数
【发布时间】:2017-12-21 08:30:27
【问题描述】:

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

【问题讨论】:

  • 好的。我想通了 :) 应该是 swiper.stop.autoplay & swiper.start.autoplay
  • 其实是:swiper.autoplay.stop()swiper.autoplay.start()

标签: javascript jquery swiper


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

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

    swiper[i].autoplay.stop();
    

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

    swiper[i].autoplay.start();
    

    感谢@nick 上面的回答,我才得以运行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-01
      • 2019-06-24
      • 1970-01-01
      • 1970-01-01
      • 2020-06-28
      • 1970-01-01
      • 1970-01-01
      • 2017-10-03
      相关资源
      最近更新 更多