Sliding screen Touchstart: triggered when touching the screen, Touchmove: Active process triggered, touchend: triggered when leaving the screen
First get the coordinates x, y when the hand touches the screen
Get x and Y when touching the screen
$ ('body'). Bind ('touchstart', function (e) { = e.originalevent.changedtouches[0].pagex, = e.originalevent.changedtouches[0 ].pagey;});
It then obtains the sliding coordinates and subtracts the previous coordinates with the following coordinates, judging the direction of its slide by the obtained value. Because the hand slide direction is generally not horizontal or vertical, so can use Math.Abs () to compare, for example: slide in the upper right corner, when the distance is greater than the distance to the right, take it up to the distance, that is, sliding upward.
$('Body'). Bind ('Touchmove', Function (e) {//get x, y when sliding the screenEndX = e.originalevent.changedtouches[0].pagex, EndY= e.originalevent.changedtouches[0].pagey; //Get sliding distanceDistancex = endx-StartX; Distancey= endy-Starty; //judging the sliding direction if(Math.Abs (Distancex) >math.abs (distancey) && distancex>0) {Console.log ('Swipe Right'); }Else if(Math.Abs (Distancex) >math.abs (distancey) && distancex<0) {Console.log ('Swipe left'); }Else if(Math.Abs (Distancex) <math.abs (distancey) && distancey<0) {Console.log ('swipe up'); }Else if(Math.Abs (Distancex) <math.abs (distancey) && distancey>0) {Console.log ('Swipe down'); }Else{Console.log ('Click Not sliding'); }});
Touchstart,touchmove to determine the direction of the slide screen in the phone