Jump to Table of Contents

The tap Event

The event-tap module creates a synthetic 'tap' event, that allows for fast-click on touch devices, while supporting mouse events as well.

On touch devices (especially iOS), listening to 'click' events usually results in a 300ms delay, as the browser waits to see if the user executes a double-click. This slight delay can result in a worsened user-experience. This module aims to correct that by providing the synthetic 'tap' event to listen to. By listening to 'tap', application developers can develop against touch events when they are supported, and fall back to pointer-based input devices.

Using Tap

To have access to the tap event, you will need to include event-tap in your use statement. Optionally, you could include the entire event module, although this isn't recommended unless you need all the functionality that event provides.

The tap synthetic event listens to the following DOM events:

Touch supported Touch not supported
touchstart mousedown
touchmove mousemove
touchend mouseup
touchcancel mousecancel

The easiest way to use tap is to convert your 'click' event listeners to listen for 'tap' instead.

node.on("tap", function (event) {
    this.addClass("tapped");
});

Tap allows for fast-clicking on touch devices and reverts to mouse events, so it behaves the same way as 'click' on pointer-based devices.

Delegating Taps

The event-tap module supports event delegation, so you can set up a single event listener to listen for events on all child elements.

myParentNode.delegate("tap", function (event) {
    this.addClass("tapped");
}, 'li a');

Features

The event-tap module has the following functionality baked in to it:

  • 'tap' only fires if there is one finger on the touchscreen.
  • 'tap' does not fire if a 'touchmove' or 'mousemove' is fired. This means that if there is any movement of the finger or pointer, 'tap' will not fire.
  • 'tap' does not fire for right mouse button clicks.

Caveats and other information

As of now, event-tap does not work on Windows 8 Tablets. Windows 8 does not support 'touchstart', 'touchmove', 'touchend', and 'touchcancel'. Instead, it uses MSPointer events.

Click Events on Touch Devices

A click event is still fired after the tap event on touch devices. This can be useful to developers since input elements will not reflect their true value on tap. For example, a radio button will not reflect the correct state on tap, but will on click. For this reason, it's best to use the tap event callback as a way to improve your user experience, and use the click event callback to listen for DOM updates. On mouse-based devices, the click event and tap event are fired simultaneously since tap falls back to mouse events in the absence of touch support.