Mobile Phone Touch Screen JS events, Mobile Phone Touch Screen JS events

Source: Internet
Author: User

Mobile Phone Touch Screen JS events, Mobile Phone Touch Screen JS events

Processing Touch events allows you to track the position of each finger of a user. You can bind the following four Touch events:


Touchstart: // triggered when the finger is placed on the screen
Touchmove: // triggered when the finger moves on the screen
Touchend: // triggered when the finger is picked up from the screen
Touchcancel: // triggered when the system cancels the touch event. When will the system be canceled? Unknown

Client/clientY: // The Position of the touch point relative to the browser window viewport
PageX/pageY: // The Position of the touch point relative to the page
ScreenX/screenY: // position of the touch point relative to the screen
Identifier: // unique ID of the touch object

 

Each Touch object contains the following attributes.

ClientX: Touch the X coordinate of the target in the viewport.
ClientY: Touch the Y coordinate of the target in the viewport.
Identifier: 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 coordinate of the DOM node to be touched.

// Touchstart event function touchSatrtFunc (e) {// evt. preventDefault (); // var touch = e. touches [0]; // obtain 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 (); // var touch = evt, such as browser scaling and scroll bar scrolling, when the touch is blocked. touches [0]; // obtain the first contact var x = Number (touch. pageX); // page contact X Coordinate var y = Number (touch. pageY); // page contact Y coordinate var text = 'touchmove event triggering :( '+ x +', '+ y + ')'; // determine the moving direction if (x-startX! = 0) {// sliding left and right} if (y-startY! = 0) {// slide up and down }}
How to use javascript to determine whether the touch screen or mouse is used

The mouse event is supported by all browsers. A common touch-screen mobile phone can also use a usb otg External mouse.

So you can only determine whether the browser supports touch screen. The key here is
[Ontouchstart, ontouchmove, ontouchend, ontouchcancel]
Browsers that support touch screens all have these four touch events.

Window. onload = function () {if (document. hasOwnProperty ("ontouchstart") {alert ("");} else {alert (" ");}};

Css or js touch screen events

Ontouchstart and ontouchend

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.