旁观自己 善待朝夕|

猫老板的豆

园龄:9年4个月粉丝:52关注:0

H5移动端判断手势滑动方向

移动端判断手势滑动方向

$("body").on("touchstart", function(e) {
	e.preventDefault();
	startX = e.originalEvent.changedTouches[0].pageX,
	startY = e.originalEvent.changedTouches[0].pageY;
});
$("body").on("touchmove", function(e) {
	e.preventDefault();
	moveEndX = e.originalEvent.changedTouches[0].pageX,
	moveEndY = e.originalEvent.changedTouches[0].pageY,
	X = moveEndX - startX,
	Y = moveEndY - startY;
	if(Math.abs(X) > Math.abs(Y) && X > 0) {
		alert("从左到右滑动");
	} 
	if(Math.abs(X) > Math.abs(Y) && X < 0) {
		alert("从右到左滑动");
	} 
	if(Math.abs(Y) > Math.abs(X) && Y > 0) {
		alert("从上到下滑动");
	}
	if(Math.abs(Y) > Math.abs(X) && Y < 0) {
		alert("从下到上滑动");
	} 
});

本文作者:猫老板的豆

本文链接:https://www.cnblogs.com/bingcola/p/16499327.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   猫老板的豆  阅读(280)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起
  1. 1 404 not found REOL
404 not found - REOL
00:00 / 00:00
An audio error has occurred.