Analysis of the principle of JS touch touch screen

Source: Internet
Author: User

Before we did a lot of touch screen effects, then, today, we will analyze the next JS touch screen principle. In fact, we Baidu a bit JS touch can basically find this article "Fingertip js--multi-touch web front-end development one: for touch processing", I think this article many beginners JS touch people have seen.

Let's illustrate it by example today. In the realization of touch screen, we must use JS AddEventListener, and then add Touchstart,touchmove,touchend. Today we add jquery to the code, just to get the ID and CSS, hehe, after all, jq everyone is using. But for the addition of events, we still have to use Document,getelementbyid this mode, because this thing only JS, jquery does not touch such things.

As you can see, in the code there is this sentence, E.preventdefault (), if you do not write this sentence, you touch the screen, the page will slide, so its role is huge ...

E.touches[0] What does it mean? Is the first in the gesture, we think is touch bar, touch screen and other two finger gestures, we learn a kind of today, ah ...

We achieved the left,top of the image and the touch screen position of the hand, then, Touchstart finished ...

Our Isdrag is used to determine whether we can drag, we use the position of the hand drag after the position of the image minus Touchstart, we can get the position after the move, so we completed the Touchmove this process.

For Touchend, we write a ifdrag=false, which means no more dragging ...

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.