<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0, minimal-ui"> <meta name="apple-mobile-web-app-capable" content="yes" /> <title>判断手指左右滑动</title> <script src="http://libs.baidu.com/jquery/1.11.3/jquery.min.js"></script> </head> <body> 判断手指滑动上下左右方向 <script type="text/javascript"> var windowHeight = $(window).height(), $body = $("body"); $body.css("height", windowHeight); var startX, startY, moveEndX, moveEndY, X, Y; $("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("左到右"); } else if ( Math.abs(X) > Math.abs(Y) && X < 0 ) { alert("右到左"); } else if ( Math.abs(Y) > Math.abs(X) && Y > 0) { alert("上到下"); } else if ( Math.abs(Y) > Math.abs(X) && Y < 0 ) { alert("下到上"); } else{ alert("just touch"); } }); </script> </body> </html>