Touch events on the phone

Source: Internet
Author: User

Source: http://www.2cto.com/kf/201401/272575.html

First, touch events on the phone

Basic event:  touchstart  //trigger when finger is just touching the screen touchmove    //finger is triggered when moving on screen touchend    //finger is triggered when moving away from the screen   Below this less use: Touchcancel  //touch process is canceled when the system triggers each event has the following list, such as Touchend targettouches of course is 0:  touches        //List of all fingers on the screen targettouches  //List of all fingers located on the element changedtouches  // List of all fingers that involve the current event each event has a list, and each list has the following properties:  copy code where coordinates are used Pagex,pagey:pagex    //relative to the X-coordinate of the page pagey    // Relative to the y-coordinate of the page Clientx  //relative to the viewport's x-coordinate clienty  //relative to the viewport's y-coordinate screenx  //relative to the x-coordinate of the screen Screeny  //relative to the y-coordinate of the screen &NB Sp;identifier//The unique number of the current touch point target  //The DOM element that the finger touches to copy code other related events:  event.preventdefault ()  /block Touch browser Zoom, scroll bar scrolling var Supporttouch = "Createtouch" in document  //to determine if touch events are supported more in-depth content? Click:http://www.cesclub.com/bw/jishuzhongxin/webjishu/2011/1216/18069.html   , Example   Here are the different types of code to get the specific method of sliding, combined with previous ideas, encapsulated, can learn from learning:  Copy code var touchfunc = function (obj,type,func) {   // Slide range within 5x5 do click Processing, S is start, E is end     Var init = {x:5,y:5,sx:0,sy:0,ex:0,ey:0};    var stime = 0, etime = 0;    type = Type.tolowercase ();  &nb Sp   Obj.addeventlistener ("Touchstart", function () {        stime = new Date (). GetTime ();  nbsp     INIT.SX = event.targettouches[0].pagex;        init.sy = Event.targettouches[0].pagey;         Init.ex = init.sx;        Init.ey = init.sy;        IF (Type.indexof ("start")! =-1) func ();   }, False);     Obj.addeventlistener ("Touchmove", function () {        event.preventdefault ();//Browser zoom when blocking touch, scroll bar scrolling         INIT.EX = E vent.targettouches[0].pagex;        Init.ey = event.targettouches[0].pagey;      & nbsp if (Type.indexof ("move")!=-1) func ();   }, False);     Obj.addeventlistener ("Touchend", function () {        var Changex = init.sx-init.ex;        var changey = init.sy-init.ey;        I F (Math.Abs (Changex) >math.abs (changey) &&math.abs (changey) >init.y) {           //Around events             if (Changex > 0) {            &NBSP ;   if (Type.indexof ("left")!=-1) func ();           }else{        &NB Sp       if (Type.indexof ("right")!=-1) func ();           }       }        ELSE if (Math.Abs (changey) >math.abs (Changex) &&math.abs (Changex) > Init.x) {           //up/down events             if (Changey > 0) {&nbs P               if (Type.indexof ("top")!=-1) func ();          &NB Sp }else{               if (Type.indexof ("Down")!=-1) func ();           }  & nbsp    }        ELSE if (Math.Abs (Changex) <init.x && math.abs (changey) <init.y) {             etime = new Date (). GetTime ();           //click events, here Breakdown by Time difference             if ((etime-stime) >) {                if (Type.indexof ("Long")!=-1) func (); Long press            }            Else {                if (Type.indexof ("click")!=-1) func (); When clicking Process            }       }        if (type.indexof ("End")!=-1) func ();   }, False);};

Touch events on the phone

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.