• This repository has been archived on 09/Jun/2022
  • Stars
    star
    18,668
  • Rank 1,399 (Top 0.03 %)
  • Language
    HTML
  • License
    MIT License
  • Created almost 13 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Polyfill to remove click delays on browsers with touch UIs

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.

<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:

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.

More Repositories

1

ftscroller

FTScroller is a cross-browser Javascript/CSS library to allow touch, mouse or scrollwheel scrolling within specified elements, with pagination, snapping and bouncing support.
JavaScript
1,186
star
2

ftcolumnflow

A polyfill that fixes the inadequacies of CSS column layouts
JavaScript
633
star
3

ftellipsis

Multi-line ellipsis made possible
JavaScript
486
star
4

fruitmachine

View rendering engine
JavaScript
247
star
5

transcription-service

A Node.js server that accepts audio/video files and transcribes the content
JavaScript
61
star
6

ftdatasquasher

Data compression and decompression support, packing base64 into UTF8 high and low bytes
JavaScript
39
star
7

big-ft

A view of the FT homepage designed for non-interactive video walls and billboards
JavaScript
23
star
8

perf-widget

JavaScript
22
star
9

Hancock

A Node.js module for determining a similarity between handwritten signatures.
JavaScript
17
star
10

text-summarization-experiment

Experiment on text summarization techniques and exploring Tensorflow.
Jupyter Notebook
15
star
11

three-sixty-video

Experiment with converting 360videos to VR.
JavaScript
14
star
12

screens

A way to distribute websites to multiple displays
JavaScript
12
star
13

single-frame-video

Simple service to convert mp3s to mp4s with images for social networks
Handlebars
8
star
14

alignment

exploring Go, aligning some text, looking for poetry, for faux-artistic reasons
Roff
8
star
15

tech-radar

Generate tech-radars based off of Google Spreadsheets
JavaScript
7
star
16

autovoice-podcast

take in an rss feed of articles, return a podcast of those articles with automated voices
JavaScript
7
star
17

inklink

Image recognition tool
JavaScript
6
star
18

email-signatures

A Chrome Extension that automagically adds links from RSS feeds to the end of emails sent in the Gmail web client
JavaScript
6
star
19

Signature-Signatures

A small exploration to try to match handwritten signatures by generating a fingerprint out of the number of black pixels along the Y Axis of the image
JavaScript
6
star
20

fruitmachine-media

FruitMachine helper that allows different setup and teardown callbacks to be called based on media queries
JavaScript
6
star
21

googlehome

Experimenting with what is possible with via voice commands on the Google Home
JavaScript
4
star
22

textrequireify

Browserify transform that includes text files using `requireText('module/filename')` syntax.
JavaScript
4
star
23

gpt2-gui

GPT-2 prototype/investigation
Python
3
star
24

Screens-Chrome-App

A kiosk-enabled app for Chrome to use with FT Labs Screens project
JavaScript
3
star
25

chatbot

An FT bot
JavaScript
3
star
26

o-three-sixty

Three Sixty Video Player powered by Brightcove
JavaScript
3
star
27

overview

Exploration(s) of summarising and displaying news
JavaScript
3
star
28

cite-n-snap

JavaScript
3
star
29

ftlabs.github.io

porting the team blog to github pages
HTML
2
star
30

idiom-explorer

whimsical investigation into use of idioms in news articles
JavaScript
2
star
31

suggestr

Recommendation algorithm(s)
JavaScript
2
star
32

Listen-to-the-FT

Make podcasts great again.
JavaScript
2
star
33

correlations-game-test

Trying out Alexa testing via Mocha
JavaScript
2
star
34

fruitmachine-ftdomdelegate

An ftdomdelegate plugin for FruitMachine
JavaScript
2
star
35

audio-search

Want to find audio content on the FT? No problem!
JavaScript
2
star
36

Twitter-digest

Chrome extension for Twitter filtering
JavaScript
2
star
37

webtorrent-audio

Where possible, deliver audio files to clients using WebTorrent
JavaScript
2
star
38

fruitmachine-bindall

A FruitMachine helper that binds all the methods in FruitMachine modules to each instance
JavaScript
2
star
39

barcode

An API endpoint to gather all of the main images used in FT articles from a provided date range, the last 24 hours for example, and squash them (width wise) to give one condensed image that represents the news. The final result looks similar to a coloured barcode.
JavaScript
2
star
40

ft-quiz

Automated quiz api for news in specified date range.
JavaScript
1
star
41

key-fetch

Get keys for your project
JavaScript
1
star
42

ft-dash

A minimal view of FT content designed for as a HUD for car dashboards
JavaScript
1
star
43

Absorber

The (newly separated) absorber component of the Ingestion service.
JavaScript
1
star
44

PPS

Product Project Summariser
JavaScript
1
star
45

left

Handlebars
1
star
46

inshort

JavaScript
1
star
47

email-signatures-server

JavaScript
1
star
48

summarize

1
star
49

assistant-authenticator

A service for ephemerally linking an FT user to a Google Home device
JavaScript
1
star
50

fruitmachine-fastdom

A fastdom helper for FruitMachine
JavaScript
1
star
51

touchbar-news

It puts the news on your shiny Macbook's Touch Bar
JavaScript
1
star
52

correlations-game

A Node.js app for playing the FT Labs Correlation game
HTML
1
star
53

Interrogable-Articles-Demo

A PWA to demonstrate the concept of 'interrogable' articles
JavaScript
1
star
54

audio-available

A small Node.js app for checking whether or not an audio version of an FT article exists.
JavaScript
1
star
55

correlations-service

exploring a node version of slurp which was a ruby version of a graph db
JavaScript
1
star
56

time-to-read

A lambda that provides the reading time from a text and image input.
JavaScript
1
star
57

FT-Labs-AWS-Archives

A PoC for having AWS OCR the entire FT Digital Archive
JavaScript
1
star
58

Falcon-Snippets

Content scripts for manipulating FT content on the Falon ft.com site
JavaScript
1
star
59

chars-to-wav

Letters in, sounds out
JavaScript
1
star
60

audio-management

A place for managing audio assets at the FT
Handlebars
1
star
61

js-abbreviate

Takes *any* JavaScript object and returns a JSON-serializable finite-sized copy of it.
JavaScript
1
star
62

order-order

A swiss army knife of various forms of structured comments.
JavaScript
1
star
63

pages

experiments with simple static pages
JavaScript
1
star
64

fruitmachine-boundarize

FruitMachine helper to isolate components from the rest of the DOM tree
JavaScript
1
star
65

boilerplates

some simple, no-nonsense examples of things
HTML
1
star