js-Resolving latency issues for mobile-click events

Source: Internet
Author: User

As we all know, the Click event on the phone will have a delay of 300ms problem. However, we need to cancel this delay when we do some small game on the mobile phone side.

The first step: Prohibit page zoom

    1. <Meta name="viewport" content= "width=device-width user-scalable= ' no '">

This piece of content can solve some of the problems of mobile phones

Step Two: fastclick.js

Fastclick is a lightweight library developed by FT Labs specifically to address the 300 millisecond Click Latency issue for mobile browsers. In short, when the Touchend event is detected, Fastclick immediately triggers a simulated click event via DOM custom events and blocks the browser from the Click event that was actually triggered after 300 milliseconds. Use the following method.

1: Introduce the Fastclick.js file in the page.

2: Add the following code to the JS file
After the window load event, the body is raised with Fastclick.attach ().

Window.addeventlistener (function () {

Fastclick.attach (document.body);

},false);

If you are using a jquery plugin

$ (function () {

Fastclick.attach (document.body);

});

I use the code here.

<script src= "Js/fastclick.js" ></script>

Handling Mobile Click Latency
if (' AddEventListener ' in document) {
Document.addeventlistener (' domcontentloaded ', function () {
Fastclick.attach (document.body);
}, False);
}

js-Resolving latency issues for mobile-click events

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.