当前位置: 移动技术网 > IT编程>开发语言>JavaScript > jquery实现相册一下滑动两次的方法教程

jquery实现相册一下滑动两次的方法教程

2019年03月31日  | 移动技术网IT编程  | 我要评论

本文实例讲述了jquery实现相册一下滑动两次的方法。分享给大家供大家参考。具体实现方法如下:

var t1=null; //定义为全局变量

$('body').on('touchstart', '#galleryslider img', function(e){
var touch = e.originalevent,
startx = touch.changedtouches[0].pagex;
if (t1 == null){
    t1 = new date().gettime();
}else{    
    var t2 = new date().gettime();
    if(t2 - t1 < 500){
      t1 = t2;
      return;
    }else{
      t1 = t2;
    }
}

slider.on('touchmove',function(e){
event.stoppropagation();
touch = e.originalevent.touches[0] ||
e.originalevent.changedtouches[0];

if(touch.pagex - startx > 10){
slider.off('touchmove');
showprevious();
}
else if (touch.pagex - startx < -10){
slider.off('touchmove');
shownext();
}
});
return false;
}).on('touchend',function(){
slider.off('touchmove');
});

当手指滑动开始的时候记录下时间,结束的时候在记录下时间,如果两个时间差相隔很近,就结束。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网