我遇到了滑键滑块的问题。我希望我的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>
答案 0 :(得分:1)
在版本4.3.5
中,您必须使用autoplay.stop
和autoplay.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的上述回答,我得以使它运行起来。