+0
日增长
18,486
stars
3,108
forks
2
watchers
207
prs
393
issues
3
releases
README
FastClick
FastClick is a simple, easy-to-use library for eliminating the 300ms delay between a physical tap and the firing of a click event on mobile browsers. The aim is to make your application feel less laggy and more responsive while avoiding any interference with your current logic.
FastClick is developed by FT Labs, part of the Financial Times.
Note: As of late 2015 most mobile browsers - notably Chrome and Safari - no longer have a 300ms touch delay, so fastclick offers no benefit on newer browsers, and risks introducing bugs into your application. Consider carefully whether you really need to use it.
Explication en français.
日本語で説明。
Why does the delay exist?
According to Google:
...mobile browsers will wait approximately 300ms from the time that you tap the button to fire the click event. The reason for this is that the browser is waiting to see if you are actually performing a double tap.
Compatibility
The library has been deployed as part of the FT Web App and is tried and tested on the following mobile browsers:
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 it isn't needed
FastClick doesn't attach any listeners on desktop browsers.
Chrome 32+ on Android with width=device-width in the viewport meta tag doesn't have a 300ms delay, therefore listeners aren't attached.
html
Same goes for Chrome on Android (all versions) with user-scalable=no in the viewport meta tag. But be aware that user-scalable=no also disables pinch zooming, which may be an accessibility concern.
For IE11+, you can use touch-action: manipulation; to disable double-tap-to-zoom on certain elements (like links and buttons). For IE10 use -ms-touch-action: manipulation.
Usage
Include fastclick.js in your JavaScript bundle or add it to your HTML page like this:
html
The script must be loaded prior to instantiating FastClick on any element of the page.
To instantiate FastClick on the body, which is the recommended method of use:
js
if ('addEventListener' in document) {
document.addEventListener('DOMContentLoaded', function() {
FastClick.attach(document.body);
}, false);
}
Or, if you're using jQuery:
js
$(function() {
FastClick.attach(document.body);
});
If you're using Browserify or another CommonJS-style module system, the FastClick.attach function will be returned when you call require('fastclick'). As a result, the easiest way to use FastClick with these loaders is as follows:
js
var attachFastClick = require('fastclick');
attachFastClick(document.body);
Minified
Run make to build a minified version of FastClick using the Closure Compiler REST API. The minified file is saved to build/fastclick.min.js or you can download a pre-minified version.
Note: the pre-minified version is built using our build service which exposes the FastClick object through Origami.fastclick and will have Top issues
#358InvalidStateError when input[type=number] is focused39 comments · 2015-01-17#268[Safari iOS] Select inputs closes on fast tap since issue #226 fix35 comments · 2014-06-19#549Clicks stop working on iOS 11.3 after resuming34 comments · 2018-04-10#548can not bring up keyboard instantly in ios 11.325 comments · 2018-04-04#422Is this library maintained?19 comments · 2015-08-17#227iOS 7 - cancel tap when stopping a scroll19 comments · 2014-03-18#36focus triggered on incorrect field after scroll.19 comments · 2012-11-29#450Disable on iOS 9.3+12 comments · 2016-01-11