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 > 0 ){ 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("向上") }