js-Mobile judgment pull-up and slide

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.