我遇到了滑键滑块的问题。我希望我的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>
在4.3.5
版本中,你必须使用autoplay.stop
和autoplay.start
。例如:
var mySwiper = new Swiper('.my-swiper');
$('.my-swiper').hover(function() {
mySwiper.autoplay.stop();
}, function() {
mySwiper.autoplay.start();
});