MENU

Swiper-解决display:none重新加载后以及手动滑动后不滑动问题

May 4, 2023 • Api接口

display:none重新加载不滑动:
原因是一开始加载Swiper没有获取到内容,需要使用对应的mySwiper.init(); 重新调用初始化加载。

手动滑动后不滑动:
Swiper3.X:

let mySwiper = new Swiper('.swiper', {
    direction: 'vertical',
    autoplay: 2500,
    spaceBetween: 10,
    loop: true, //循环滚动
    autoplayDisableOnInteraction: false //用户操作swiper之后,是否禁止autoplay。默认为true:停止。
    如果设置为false,用户操作swiper之后自动切换不会停止,每次都会重新启动autoplay。
});

Swiper4.X:

let mySwiper = new Swiper('.swiper', {
    direction: 'vertical',
    spaceBetween: 10,
    loop: true, //循环滚动
    autoplay: {
        delay:2500,
        disableOnInteraction:false,//用户操作swiper之后,是否禁止autoplay。默认为true:停止。
        如果设置为false,用户操作swiper之后自动切换不会停止,每次都会重新启动autoplay。
    },
    
});
Last Modified: June 7, 2023