swiper监听滚动条_swiper插件怎么监听滑动事件?
var startY,startX,endX,endY;
var mySwiper = new Swiper(.swiper-container,{
preventClicks : true,
pagination: .swiper-pagination,
paginationClickable: .swiper-pagination,
preventLinksPropagation : true,
spaceBetween: 30,
effect: fade,
onSlideChangeEnd:function(swiper){
alert(swiper.activeIndex+);
// swiper.activeIndex 这个就是索引, 从 0 开始! 可看一共有多少元素!
},
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){
if(Math.abs(endX)>5){
endX=0;
return false;
}else{
var href;
switch (swiper.index){
case 1:
href = "https://m.jrj.com.cn/yi/prd/prdxq?type=sr";
case 2:
href = "https://m.jrj.com.cn/yi/prd/prdxq?type=sr";
case 3:
href = "https://m.jrj.com.cn/yi/prd/prdxq?type=sr";
case 4:
href = "https://m.jrj.com.cn/yi/prd/prdxq?type=sr";
}
self.location = href;
endX=0;
}
}
});
HTML
var startY,startX,endX,endY; var mySwiper = new Swiper(.swiper-container,{ preventClicks : true, pagination: .swiper-pagination, paginationClickable: .swiper-pagination, preventLinksPropagation : true, spaceBetween: 30, effect: fade, onSlideChangeEnd:function(swiper){ alert(swiper.activeIndex+); // swiper.activeIndex 这个就是索引, 从 0 开始! 可看一共有多少元素! }, 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){ if(Math.abs(endX)>5){ endX=0; return false; }else{ var href; switch (swiper.index){ case 1: href = "https://m.jrj.com.cn/yi/prd/prdxq?type=sr"; case 2: href = "https://m.jrj.com.cn/yi/prd/prdxq?type=sr"; case 3: href = "https://m.jrj.com.cn/yi/prd/prdxq?type=sr"; case 4: href = "https://m.jrj.com.cn/yi/prd/prdxq?type=sr"; } self.location = href; endX=0; } } }); HTML