关于swiper移动端的坑

这里讲的是swiper兼容移动端的问题

为了提高移动端的加载速度,开发人员手动拿出需要的siwper的样式和js是ok的,
但是这里需要需要注意几点

  • 移动端上的卡顿问题
  • 官方建议代码

移动端上的卡顿问题

如果只引用了swiper的js而没有引入swiper.css和swiper.animate.js,移动端就会出现卡顿问题

<link rel="stylesheet" href="../../styles/library/swiper.min.css"/>  
<script src="../../scripts/common/swiper-3.3.1.min.js"></script>  
<script src="../../scripts/common/swiper.animate.min.js"></script>  

官方建议代码

下面的代码是解决在安卓app出现的问题:切换不流畅

// 轮播图--左右滑动和切换  
   var mySwiper = new Swiper('.swiper-container',{  
       pagination: '.pagination',  
       loop:false,  
       mode: 'horizontal',  
       freeMode:false,  
       touchRatio:0.5,  
       longSwipesRatio:0.1,  
       threshold:50,  
       followFinger:false,  
       observer: true,//修改swiper自己或子元素时,自动初始化swiper  
       observeParents: true,//修改swiper的父元素时,自动初始化swiper  
       onSlideChangeEnd:function(swiper){ // 当滑动结束后---月份日期切换同步左右左右切换  
           changeMonth();  
       }  
   });  

灵感来自于@京都玩家

猜你喜欢

转载自blog.csdn.net/cx091/article/details/78280061