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) { StartX = E.originalevent.changedtouches[0].pagex, starty = 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) { //x/y EndX = E.originalevent.changedtouches[0].pagex when getting the sliding screen , EndY = e.originalevent.changedtouches[0].pagey; Get sliding distance Distancex = endx-startx; Distancey = Endy-starty; Determine 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