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
Gets the X and y$ (' body ') when touching the screen. 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;
var Distancex = Moveendx-startx;
var distancey = Moveendy-starty;
if (Math.Abs (Distancex) > Math.Abs (distancey) && Distancex > 0) {
Alert ("You swipe right! ");
}
else if (Math.Abs (Distancex) > Math.Abs (distancey) && Distancex < 0) {
Alert ("You swipe left! ");
}
else if (Math.Abs (Distancex) < Math.Abs (Distancey) && distancey > 0) {
Alert ("You swipe down! ");
}
else if (Math.Abs (Distancex) < Math.Abs (Distancey) && Distancey < 0) {
Alert ("You swipe up! ");
}
else {alert ("You have turned a lot of circles back to the origin!! "); }
});
By the way:
1, Math.Abs (); the function is used to obtain the absolute value of positive and negative numbers;
2, the binding element of the event is to be written in when the page load is completed after the event, or is encapsulated into a function, in the page loading the last line call;
3, e.originalevent.changedtouches[0].pagey/x, I write when the changedtouches is not intelligent tips, need to be careful and attention;
I hope you have some help, good study, day up!!
Judgment on the direction of mobile gesture sliding (mode one)