disableOnInteraction
用户操作swiper之后,是否禁止autoplay。默认为true:停止。
如果设置为false,用户操作swiper之后自动切换不会停止,每次都会重新启动autoplay。
操作包括触碰(touch),拖动,点击pagination等。
<script>
var mySwiper = new Swiper('.swiper-container',{
autoplay: {
disableOnInteraction: false,
},
})
</script>
有时候,隐藏了swiper后再显示,就会出现不自动切换的情况,就需要手动将swiper启动播放和停止播放。
代码如下:
<script language="javascript">
var mySwiper = new Swiper('.swiper',{
autoplay : true,
})
//鼠标覆盖停止自动切换
mySwiper.el.onmouseover = function(){
mySwiper.autoplay.stop();
}
//鼠标离开开始自动切换
mySwiper.el.onmouseout = function(){
mySwiper.autoplay.start();
}
</script>