Mobile-side events Touchstart, Touchmove, Touchend

Source: Internet
Author: User

About these three mobile events, detailed information on the Internet a large search, I will not waste time

1. Mobile End Long press event

var NULL ; $ (ele). On (' Touchstart ',function() {    = setTimeout (function() {        Alert ("I am the long-press event!") ")    }); $ (Ele). On (' touchend ',function() {    cleartimeout (timer);});

Description: Simulates a long-press event via a timer, this example is based on jquery, where "ele" is the element to be long pressed;

2. Swipe up or down events on the mobile side

<! DOCTYPE html>//left and right swipe eventsvarStartX = 0, Starty = 0;functionTouchsatrtfunc (evt) {Try{evt.preventdefault ();//Browser zoom, scroll bar scrolling, and so on when blocking touch        vartouch = evt.touches[0];//get the first touch point        varx = number (Touch.pagex);//page contact X coordinate        vary = number (touch.pagey);//page Contact Y coordinate        //Record Contact initial positionStartX =x; Starty=y; }    Catch(e) {alert (' Touchsatrtfunc: ' +e.message); }}functionTouchmovefunc (evt) {Try{evt.preventdefault ();//Browser zoom, scroll bar scrolling, and so on when blocking touch        vartouch = evt.touches[0];//get the first touch point        varx = number (Touch.pagex);//page contact X coordinate        vary = number (touch.pagey);//page Contact Y coordinate        vartext; //Judging slide left and right direction        if(x-startx>=30) {text= ' Swipe right '; document.getElementById (' TOUCHLR '). InnerHTML =text; }Else if(x-startx<=-30) {text= ' swipe left '; document.getElementById (' TOUCHLR '). InnerHTML =text; }        //Judging slide up and down direction        if(y-starty>=30) {text= ' Swipe down '; document.getElementById (' TOUCHLR '). InnerHTML =text; }Else if(y-starty<=-30) {text= ' swipe up '; document.getElementById (' TOUCHLR '). InnerHTML =text; }    }    Catch(e) {alert (' Touchmovefunc: ' +e.message); }}functionbindevent () {Document.addeventlistener (' Touchstart ', Touchsatrtfunc,false); Document.addeventlistener (' Touchmove ', Touchmovefunc,false);} Bindevent ();</script></body>

Description: The specific principle of a search a bunch of concrete examples here, the copy can be used; my way of learning is that, no matter what the principle, the first thing to do is to get the demand out, the principle of the elusive;

Mobile-side events Touchstart, Touchmove, Touchend

Related Article

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.