Top Related Projects
InstantClick makes following links in your website instant.
Polyfill for the HTML dialog element
A Library for creating beautiful mobile shelfs in Javascript (Facebook and Path style side menus)
FTScroller is a cross-browser Javascript/CSS library to allow touch, mouse or scrollwheel scrolling within specified elements, with pagination, snapping and bouncing support.
Simple library for handling keyboard shortcuts in Javascript
Quick Overview
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.
Pros
- Improves responsiveness of touch events on mobile devices
- Easy to implement with minimal code changes
- Works across various mobile browsers and platforms
- Lightweight and has no dependencies
Cons
- No longer actively maintained (last commit was in 2016)
- May conflict with some modern frameworks that have their own touch event handling
- Can potentially interfere with native browser behaviors in some cases
- Not necessary for newer browsers that have addressed the 300ms delay issue
Code Examples
- Basic usage:
document.addEventListener('DOMContentLoaded', function() {
FastClick.attach(document.body);
}, false);
This code attaches FastClick to the entire document body when the DOM content is loaded.
- Selective application:
var element = document.getElementById('my-element');
FastClick.attach(element);
This example shows how to apply FastClick to a specific element rather than the entire document.
- Ignoring certain elements:
FastClick.attach(document.body, {
ignore: '.no-fastclick'
});
This code attaches FastClick to the document body but ignores elements with the 'no-fastclick' class.
Getting Started
To use FastClick in your project, follow these steps:
-
Install FastClick via npm:
npm install fastclick
-
Include FastClick in your JavaScript file:
import FastClick from 'fastclick';
-
Attach FastClick to your application:
document.addEventListener('DOMContentLoaded', function() { FastClick.attach(document.body); }, false);
-
That's it! FastClick is now active in your application.
Competitor Comparisons
InstantClick makes following links in your website instant.
Pros of InstantClick
- Focuses on preloading pages for faster navigation, potentially offering better overall site performance
- Simpler implementation, requiring less configuration and setup
- Works with standard links, making it easier to integrate into existing websites
Cons of InstantClick
- Limited to enhancing page navigation speed, unlike FastClick's broader touch event optimization
- May not address specific mobile device issues like the 300ms delay on touch devices
- Less actively maintained, with fewer recent updates compared to FastClick
Code Comparison
InstantClick:
instantclick.init();
FastClick:
if ('addEventListener' in document) {
document.addEventListener('DOMContentLoaded', function() {
FastClick.attach(document.body);
}, false);
}
Key Differences
InstantClick focuses on preloading pages for faster navigation, while FastClick aims to eliminate the 300ms delay between physical tap and click event on touch devices. InstantClick requires minimal setup, whereas FastClick needs to be attached to specific elements. FastClick is more suitable for mobile-specific optimizations, while InstantClick can benefit both mobile and desktop users by improving overall site navigation speed.
Use Cases
- Choose InstantClick for general website performance improvements and faster page transitions
- Opt for FastClick when developing mobile-specific applications or addressing touch event delays on mobile devices
Polyfill for the HTML dialog element
Pros of dialog-polyfill
- Focuses on enhancing native
<dialog>
element functionality across browsers - Maintained by Google Chrome team, ensuring compatibility with modern web standards
- Lightweight and specific to dialog functionality
Cons of dialog-polyfill
- Limited in scope compared to FastClick's broader touch event optimization
- May require additional styling and customization for complex dialog implementations
- Less frequently updated than FastClick
Code Comparison
dialog-polyfill usage:
var dialog = document.querySelector('dialog');
dialogPolyfill.registerDialog(dialog);
dialog.showModal();
FastClick usage:
if ('addEventListener' in document) {
document.addEventListener('DOMContentLoaded', function() {
FastClick.attach(document.body);
}, false);
}
Key Differences
- Purpose: dialog-polyfill enhances dialog functionality, while FastClick improves touch responsiveness
- Scope: dialog-polyfill is more focused, FastClick addresses broader touch event issues
- Implementation: dialog-polyfill works with native HTML elements, FastClick modifies event handling
- Maintenance: dialog-polyfill is maintained by Google Chrome team, FastClick by Financial Times Labs
Use Cases
- dialog-polyfill: Web applications requiring cross-browser dialog support
- FastClick: Mobile web apps needing improved touch responsiveness, especially on older devices
A Library for creating beautiful mobile shelfs in Javascript (Facebook and Path style side menus)
Pros of Snap.js
- Provides a sliding side menu functionality, which is not available in FastClick
- Offers more customization options for touch interactions
- Supports both left and right side menus
Cons of Snap.js
- Larger file size compared to FastClick
- More complex implementation for basic touch events
- May have performance issues on older devices due to its advanced features
Code Comparison
Snap.js initialization:
var snapper = new Snap({
element: document.getElementById('content')
});
FastClick initialization:
if ('addEventListener' in document) {
document.addEventListener('DOMContentLoaded', function() {
FastClick.attach(document.body);
}, false);
}
Key Differences
- Snap.js focuses on creating sliding side menus, while FastClick aims to eliminate the 300ms delay on touch devices
- Snap.js requires more setup and configuration, whereas FastClick can be implemented with minimal code
- FastClick is more suitable for improving overall touch responsiveness, while Snap.js is specific to creating navigation menus
Use Cases
- Choose Snap.js when building mobile web applications that require sliding side menus
- Opt for FastClick when you need to enhance touch responsiveness across your entire web application
Community and Maintenance
- FastClick has more stars and contributors on GitHub, indicating a larger community
- Snap.js has fewer recent updates, which may indicate less active maintenance
FTScroller is a cross-browser Javascript/CSS library to allow touch, mouse or scrollwheel scrolling within specified elements, with pagination, snapping and bouncing support.
Pros of ftscroller
- Specialized for smooth scrolling and momentum-based interactions
- Supports both touch and mouse input for cross-device compatibility
- Offers more advanced scrolling features like snapping and custom easing
Cons of ftscroller
- More complex implementation compared to fastclick's simplicity
- Focused solely on scrolling, while fastclick addresses tap delay issues
- Larger codebase and potentially higher overhead
Code Comparison
ftscroller:
var scroller = new FTScroller(element, {
scrollingX: true,
scrollingY: true,
snapping: true,
snapSizeX: 100,
snapSizeY: 100
});
fastclick:
if ('addEventListener' in document) {
document.addEventListener('DOMContentLoaded', function() {
FastClick.attach(document.body);
}, false);
}
Summary
ftscroller is a specialized library for creating smooth, customizable scrolling experiences across devices. It offers more advanced features but comes with increased complexity. fastclick, on the other hand, focuses on eliminating tap delays on touch devices, providing a simpler solution for improving touch responsiveness. The choice between the two depends on the specific needs of the project, with ftscroller being more suitable for projects requiring advanced scrolling functionality, while fastclick is ideal for enhancing overall touch responsiveness with minimal implementation effort.
Simple library for handling keyboard shortcuts in Javascript
Pros of Mousetrap
- Focuses on keyboard shortcuts and hotkeys, providing a more specialized solution for keyboard interactions
- Supports complex key combinations and sequences, allowing for more advanced keyboard controls
- Lightweight and has no dependencies, making it easy to integrate into various projects
Cons of Mousetrap
- Limited to keyboard interactions, lacking touch or click event handling
- May require more setup for basic keyboard shortcuts compared to FastClick's simpler implementation
- Does not address mobile-specific issues like the 300ms delay on touch devices
Code Comparison
Mousetrap:
Mousetrap.bind('ctrl+shift+k', function() {
console.log('Keyboard shortcut triggered');
});
FastClick:
document.addEventListener('DOMContentLoaded', function() {
FastClick.attach(document.body);
});
Summary
Mousetrap is specialized for keyboard interactions, offering complex shortcut handling but lacking touch support. FastClick focuses on eliminating touch delays on mobile devices, providing a simpler implementation for touch events. The choice between them depends on whether the project prioritizes keyboard shortcuts or mobile touch responsiveness.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
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.
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.
<meta name="viewport" content="width=device-width, initial-scale=1">
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:
<script type='application/javascript' src='/path/to/fastclick.js'></script>
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:
if ('addEventListener' in document) {
document.addEventListener('DOMContentLoaded', function() {
FastClick.attach(document.body);
}, false);
}
Or, if you're using jQuery:
$(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:
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 the Browserify/CommonJS API (see above).
var attachFastClick = Origami.fastclick;
attachFastClick(document.body);
AMD
FastClick has AMD (Asynchronous Module Definition) support. This allows it to be lazy-loaded with an AMD loader, such as RequireJS. Note that when using the AMD style require, the full FastClick
object will be returned, not FastClick.attach
var FastClick = require('fastclick');
FastClick.attach(document.body, options);
Package managers
You can install FastClick using Component, npm or Bower.
For Ruby, there's a third-party gem called fastclick-rails. For .NET there's a NuGet package.
Advanced
Ignore certain elements with needsclick
Sometimes you need FastClick to ignore certain elements. You can do this easily by adding the needsclick
class.
<a class="needsclick">Ignored by FastClick</a>
Use case 1: non-synthetic click required
Internally, FastClick uses document.createEvent
to fire a synthetic click
event as soon as touchend
is fired by the browser. It then suppresses the additional click
event created by the browser after that. In some cases, the non-synthetic click
event created by the browser is required, as described in the triggering focus example.
This is where the needsclick
class comes in. Add the class to any element that requires a non-synthetic click.
Use case 2: Twitter Bootstrap 2.2.2 dropdowns
Another example of when to use the needsclick
class is with dropdowns in Twitter Bootstrap 2.2.2. Bootstrap add its own touchstart
listener for dropdowns, so you want to tell FastClick to ignore those. If you don't, touch devices will automatically close the dropdown as soon as it is clicked, because both FastClick and Bootstrap execute the synthetic click, one opens the dropdown, the second closes it immediately after.
<a class="dropdown-toggle needsclick" data-toggle="dropdown">Dropdown</a>
Examples
FastClick is designed to cope with many different browser oddities. Here are some examples to illustrate this:
- basic use showing the increase in perceived responsiveness
- triggering focus on an input element from a
click
handler - input element which never receives clicks but gets fast focus
Tests
There are no automated tests. The files in tests/
are manual reduced test cases. We've had a think about how best to test these cases, but they tend to be very browser/device specific and sometimes subjective which means it's not so trivial to test.
Credits and collaboration
FastClick is maintained by Rowan Beentje, Matthew Caruana Galizia and Matthew Andrews at FT Labs. All open source code released by FT Labs is licenced under the MIT licence. We welcome comments, feedback and suggestions. Please feel free to raise an issue or pull request.
Top Related Projects
InstantClick makes following links in your website instant.
Polyfill for the HTML dialog element
A Library for creating beautiful mobile shelfs in Javascript (Facebook and Path style side menus)
FTScroller is a cross-browser Javascript/CSS library to allow touch, mouse or scrollwheel scrolling within specified elements, with pagination, snapping and bouncing support.
Simple library for handling keyboard shortcuts in Javascript
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot