JS event for mobile phone touch screen

Source: Internet
Author: User

Handling Touch events allows you to track the location of each finger of the user. You can bind the following four kinds of touch events:


Touchstart: Trigger When the finger is placed on the screen
Touchmove://Trigger when the finger moves on the screen
Touchend://Trigger when finger is picked up from the screen
Touchcancel://The system triggers when the touch event is canceled. As to when the system will be canceled, unknown

client/clienty://the location of the touch point relative to the browser window viewport
pagex/pagey://the position of the touch point relative to the page
screenx/screeny://the position of the touch point relative to the screen
Identifier://Unique ID of touch object

Each Touch object contains the following properties.

ClientX: Touch the x-coordinate of the target in the viewport.
ClientY: Touch the y-coordinate of the target in the viewport.
Identifier: Represents the unique ID of the touch.
PageX: Touch the x-coordinate of the target in the page.
Pagey: Touch the y-coordinate of the target in the page.
ScreenX: Touch the x-coordinate of the target in the screen.
ScreenY: Touch the y-coordinate of the target in the screen.
Target: The coordinates of the DOM node of the touch.

 //touchstart event   function touchsatrtfunc (e)  {      // Evt.preventdefault ()  //block Browser zoom, scroll bar scrolling, etc. when blocking touch       var touch =  e.touches[0]; //gets the first contact       var x = number (Touch.pageX);  //page Contact x coordinate       var y = number (touch.pagey)  //page Contact Y coordinate       //Record Contact initial position       startX = x;       starty = y;  }   //touchmove Event  function  touchmovefunc (e)  {      //evt.preventdefault ();  //the browser's zoom when blocking the touch, Scroll bar scrolling and other       var touch = evt.touches[0]; //get the first contact        var x = number (Touch.pagex);  //page contact x-coordinate        var y&Nbsp;= number (touch.pagey);  //page Contact y-coordinate       var text =  ' Touchmove Event Trigger: ('  + x +  ',  '  + y +  ') ';       //Judging slide Direction       if  (x - startx != 0)  {           //left       }  Right slide      if  (y - starty != 0)  {           //swipe up and down       }  }  

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.