解决
将属性href绑定在swiper-slide上动态获取
判断滑动X差值进行判断是否是在点击或者滑动状态
具体代码如下:
var startY,startX,endX,endY,oIndex;
var href = [];
$('.swiper-drag .swiper-slide').on('touchstart',function(){
oIndex = $(this).index();
})
var mySwiper = new Swiper('.swiper-drag',{
slidesPerView: 'auto',
paginationClickable: true,
slidesOffsetAfter: 16,
freeMode: true,
onTouchStart: function(swiper,event){
var touch = event.touches[0];
startY = touch.pageY;
startX = touch.pageX;
},
onTouchMove: function(swiper,event){
var touch = event.touches[0];
endX = touch.pageX-startX;
endY = touch.pageY-startY;
},
onTouchEnd: function(swiper){
// setTimeout(function(){
// },250)
if(Math.abs(endX)>5){
endX=0;
return false;
}else{
for(var i=0;i<$('.swiper-drag .swiper-slide').length;i++){
href.push($('.swiper-drag .swiper-slide').eq(i).attr('href'));
}
self.location = href[oIndex];
endX=0;
}
}
});