标签:startx code event style class 上下左右 something touch事件 math
var startX, startY, moveEndX, moveEndY; $(‘body‘).on(‘touchstart‘, function(e) { e.preventDefault(); startX = e.touches[0].pageX, startY = e.touches[0].pageY; }); $(‘body‘).on(‘touchmove‘, function(e) { e.preventDefault(); moveEndX = e.touches[0].pageX, moveEndY = e.touches[0].pageY, X = moveEndX - startX, Y = moveEndY - startY; if (Math.abs(X) > Math.abs(Y) && X > 0) {//从左往右滑 doSomethingOne(); }else if (Math.abs(X) > Math.abs(Y) && X < 0) {//从右往左滑 doSomethingTwo(); }else if(Math.abs(Y) > Math.abs(X) && Y > 0) {//从上往下滑 doSomethingThree(); }else if(Math.abs(Y) > Math.abs(X) && Y < 0) {//从下往上滑 doOtherThingFour(); } });
标签:startx code event style class 上下左右 something touch事件 math
原文地址:http://www.cnblogs.com/camille666/p/touch_up_down_left_right.html