JS Implementation Touch Mobile touch screen Slide Event

Source: Internet
Author: User

Before you begin to describe the touch event, you need to describe the touch objects that are unique to the multi-touch system (Android and iOS, and even Nokia's newest Meego systems emulate similar objects). This object encapsulates a screen touch, usually from a finger. It is generated when the touch event is triggered and can be taken from the event object of the touch events handler

The effect of mobile touch screen sliding is actually the picture carousel, which is well implemented on the PC's page, binding the click and MouseOver events to complete. But on mobile devices, to achieve this kind of carousel effect, you need to use the core touch event. Handle touch events to track each finger to the screen slide.

Here are four kinds of touch events
Touchstart: Triggers when the finger is placed on the screen
Touchmove://finger on-screen swipe trigger
Touchend://trigger when finger leaves screen
Touchcancel://The system cancels the touch event when triggered, this seems to be less use

Once each touch event is triggered, an event object is generated and the event object includes the following three touch lists in addition

Touches://List of all fingers on the current screen
Targettouches://The list of fingers on the current DOM element, try to use this instead of touches
Changedtouches://List of fingers that involve the current event, try to use this instead of touches
Each touch in these lists consists of the touch object, which contains the touching information, with the following main attributes:
Clientx/clienty://Touch point relative to the location of the browser window
Pagex/pagey://Touch point relative to the position of the page
Screenx/screeny://Touch point relative to the position of the screen
Identifier: ID of the//touch object
Target://Current DOM element

Attention:

When you swipe the entire screen, your finger affects the browser's behavior, such as scrolling and zooming. So when you invoke the touch event, be careful to suppress zooming and scrolling.

1. Disable zooming
Set with meta meta tags.

2. Disable scrolling
Preventdefault is blocking the default behavior, and the default behavior of the touch event is scrolling.
Event.preventdefault ();

Use case:

<! DOCTYPE html>

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.