码迷,mamicode.com
首页 > 其他好文 > 详细

滑动事件

时间:2019-01-14 14:54:24      阅读:236      评论:0      收藏:0      [点我收藏+]

标签:add   var   listen   fun   star   左右滑动   触摸   pagex   rtx   

tachMove(item)
function tachMove(targer){
var startx,starty,X,Y;
targer.addEventListener("touchstart",function(e){ //第一次触摸
startx = e.touches[0].pageX;
starty = e.touches[0].pageY;
});

targer.addEventListener("touchmove",function(e){ //手指屏幕滑动
X = (e.touches[0].pageX) - startx;
Y = (e.touches[0].pageY) - starty;
//判断上下左右滑动
if( Math.abs(X) > Math.abs(Y) && X > 12 ){
toRight();
}
else if( Math.abs(X) > Math.abs(Y) && X < -12 ){
toLeft()
}
else if( Math.abs(Y) > Math.abs(X) && Y > 12 ){
toBottom();
}
else if( Math.abs(Y) > Math.abs(X) && Y < -12 ){
toTop()
}
});
}
//执行函数
function toRight(){
console.log("向右")
}
function toLeft(){
console.log("向左")
}
function toBottom(){
console.log("向下")
}
function toTop(){
console.log("向上")
}

滑动事件

标签:add   var   listen   fun   star   左右滑动   触摸   pagex   rtx   

原文地址:https://www.cnblogs.com/xm16/p/10265901.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!