Fastclick.js---Resolve mobile Click event 300ms delay

Source: Internet
Author: User

Fast Click is a simple, easy-to-use library designed to eliminate 300ms latency between mobile browsers from physical touch to triggering click events.


Why is there a delay?

From the touch button to the trigger click event, the Mobile browser will wait close to 300ms, because the browser will wait to determine if you are performing a double-click event


Compatibility

    • mobile Safari on iOS 3 and upwards

    • chrome on iOS 5 and upwards

    • chrome on Android (ICS)

    • opera Mobile 11.5 and upwards

    • android Browser since Android 2

    • playbook OS 1 and upwards


When not to use

1, Fastclick will not be accompanied by listening to any desktop browser

2, Android system, in the header meta set width=device-width chrome32+ Browser does not exist 300ms delay, so, also do not need

<meta name= "viewport" content= "Width=device-width, initial-scale=1" >


3. The same situation applies to Android devices (any version) and is set in viewport user-scalable=no , but this disables the scaling of the Web page.


4, ie11+ Browser, you can use touch-action:manipulation; It is forbidden to double-click to enlarge some elements (such as: Links and buttons). IE10 can use -ms-touch-action:manipulation



How to use

Introduction of Fastclick.js in HTML pages

<script type= ' application/javascript ' src= '/path/to/fastclick.js ' ></script>


The script file must be loaded before the page element is instantiated Fastclick


To instantiate Fastclick on the body, it is recommended to use the following methods:

if (' AddEventListener ' in document) {Document.addeventlistener (' domcontentloaded ', function () {FASTCLICK.ATTAC    H (document.body); }, False);}


If you're using JQuery,

$ (function () {Fastclick.attach (document.body);});


If you are using a browserify or other CommonJS-style modular system, theFastclick.attach method will return after you call require (' Fastclick ') . So the simplest way to use Fastclick is as follows:

var Attachfastclick = require (' Fastclick '); Attachfastclick (document.body);


Example:

<! Doctype html>


Run this code through the phone, using the Fastcick event, it can be obvious that the click on the link text red when the flicker effect is not


GitHub Address: Https://github.com/ftlabs/fastclick



This article is from the "Dapengtalk" blog, make sure to keep this source http://dapengtalk.blog.51cto.com/11549574/1886507

Fastclick.js---Resolve mobile Click event 300ms delay

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.