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

touch事件之上下左右滑

时间:2017-07-30 11:38:39      阅读:166      评论:0      收藏:0      [点我收藏+]

标签: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();
  }
});

 

touch事件之上下左右滑

标签:startx   code   event   style   class   上下左右   something   touch事件   math   

原文地址:http://www.cnblogs.com/camille666/p/touch_up_down_left_right.html

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