我遇到了滑动条 slider 的问题。我希望我的刷卡器在鼠标进入时停止并在鼠标离开时继续。但是我的控制台显示错误 --> 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.stop
和 autoplay.start
。例如:
var mySwiper = new Swiper('.my-swiper');
$('.my-swiper').hover(function() {
mySwiper.autoplay.stop();
}, function() {
mySwiper.autoplay.start();
});
关于javascript - Swiper slider 报错 startAutoplay is not a function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47920898/