Ideas:
(1) Get the initial coordinates of the user's sliding finger
(2) Get the finger coordinates at the end of the user's swipe
(3) Compare the absolute value in the X, Y direction to determine whether the sliding direction is around or up or down
(4) Final actual judgment of the specific direction
/* Note Touchstart, touthmove coordinates are stored in e.targettouches[0]*//* touchend coordinates are stored in e.changedtouches[0] */var firstx = 0,firstY = 0, EndX = 0,endy = 0;//initializes the coordinate value Window.addeventlistener ("Touchstart", function (e) {firstx = E.targettouches[0].clientx; Firsty = E.targettouches[0].clienty;}) Window.addeventlistener ("Touchend", function (e) {endx = E.changedtouches[0].clientx;endy = E.changedtouches[0]. Clienty;movex = endx-firstx;//judgment left and right Movey = endy-firsty;//judging up and down if (Math.Abs (MoveX) > 60 | | Math.Abs (Movey) > 60) {//is judged to be sliding, not by clicking on if (Math.Abs (MoveX) > Math.Abs (Movey))) {/* Judging the distance between the lateral movement and the distance between the longitudinal movement, judging whether it is around or up/down * var ele = moveX > 0? "Right": "Left"; alert (ele);} Else{var ele = movey > 0? "Down": "Up"; alert (ele);}})
The mobile side determines the user's sliding direction