HTML判断手指滑动
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
</head>
<style type="text/css">
* {
touch-action: pan-y;
}
</style>
<body>
</body>
<script type="text/javascript">
var windowHeight = $(window).height(),
$body = $("body");
$body.css("height", windowHeight); //重要代码
$("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) {
console.log('left 2 right');
} else if (Math.abs(X) > Math.abs(Y) && X < 0) {
console.log('right 2 left');
} else if (Math.abs(Y) > Math.abs(X) && Y > 0) {
console.log('top 2 bottom');
} else if (Math.abs(Y) > Math.abs(X) && Y < 0) {
console.log('bottom 2 top');
} else {
console.log('just touch');
}
});
</script>
</html>