First, finger touch screen, the use of Touchstart and touchend to calculate the sliding distance before and after the judgment is pull or decline.
Second, JS in the distance: Pagey, ClientY, offsety difference:
OffsetY: The offset distance relative to the parent node.
ClientY: The roller distance is not counted relative to the browser.
Pagey: Relative to the browser, the distance of the scroll wheel is counted, in this case, with Pagey, the record position of the touch screen-starty, at the end of the record-endy, two subtraction to determine whether to move up or down.
Three, Touchstart has the touches attribute, Touchend has the changedtouches attribute, the two attribute has pagey, Pagex information respectively.
//Slide Handling varStartX, Starty; Document.addeventlistener (' Touchstart ',function(EV) {StartX= Ev.touches[0].pagex; Starty= Ev.touches[0].pagey; }, false); Document.addeventlistener (' Touchend ',function(EV) {varEndX, EndY; EndX= Ev.changedtouches[0].pagex; EndY= Ev.changedtouches[0].pagey; varDirection =getslidedirection (StartX, Starty, EndX, EndY); Switch(direction) { Case0: Alert ("No Action"); Break; Case1: //UpwardAlert ("Up"); Break; Case2: //downwardAlert ("Down"); Break; default: } }, false);
functiongetslidedirection (StartX, Starty, EndX, EndY) {varDY = starty-EndY; //var dx = endx-startx; varresult = 0; if(dy>0) {//swipe upResult=1; }Else if(dy<0) {//Swipe downresult=2; } Else{result=0; } returnresult; }
js-Mobile judgment pull-up and slide