Swiper.js使用遇到的问题总结onSlideChangeEnd回调偶尔触发,偶尔不触发等

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/xm1037782843/article/details/87981190

swiper 是一个开源免费的移动触摸插件。swiper3.0版本使用。

onSlideChangeEnd回调偶尔不触发,或者是pc端触发,但是手机端不触发

在使用中遇到这样一个问题,记录一下。

page 间切换效果 使用 fade 的时候,如果每个页面的大小不一样, 比如第一个页面全屏, 第二个页面比第一个小, 那么切换到第二页的时候, 第一页的内容还可以看到。

还有,使用 fade 过度方法,onSlideChangeEnd 回调偶尔触发,偶尔不触发。 因此使用 onTransitionEnd;

解决方案:

  1. 添加 fade:{crossFade:true}
  2. 切换之后效果, 使用 onSlideChangeEnd(page切换后触发) 会偶尔不触发, 请使用 onTransitionEnd(过度效果结束触发) 

    var mySwiper = new Swiper('.swiper-container',{<br>  pagination: '.swiper-pagination',<br>   nextButton: '.swiper-button-next',

       prevButton: '.swiper-button-prev',

       effect: 'fade',<br>// tips

    扫描二维码关注公众号,回复: 6030512 查看本文章

       fade: {

         crossFade: true,

       },

       onTransitionEnd: function (swiper) {

         console.info("页面跳转到第:", swiper.activeIndex, " 页")

       }

猜你喜欢

转载自blog.csdn.net/xm1037782843/article/details/87981190