Skip to content
This repository has been archived by the owner on May 12, 2018. It is now read-only.

Latest commit

 

History

History
90 lines (61 loc) · 2.13 KB

README.md

File metadata and controls

90 lines (61 loc) · 2.13 KB

Deprecated

TapListener is no longer support and should be avoided. From ftlabs/fastclick

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.

Likewise, TapListener is no longer useful. I recommend using standard click event.

See Chrome dev blog - 300ms tap delay, gone away

Tap listener

Listens to taps

On mobile devices, the click event is triggered after a delay. Tap Listener listens for native touch and pointer events to trigger a callback immediately.

Used in Flickity.

var tapper = new TapListener( element );
tapper.on( 'tap', function( event ) {
  console.log('tap happened');
});

Use TapListener to extend a class.

function Widget() {
  //...
}
// inherit Tap Listener
Widget.prototype = new TapListener();
// or
_.extend( Widget.prototype, TapListener.prototype );

var widgy = new Widget( element );
widgy.on( 'tap', function() {...});

Install

Bower: bower install tap-listener --save

npm: npm install tap-listener

RequireJS

requirejs( [ 'path/to/tap-listener' ], function( TapListener ) {
  var tapper = new TapListener( element );
});

Browserify

var TapListener = require('tap-listener');
var tapper = new TapListener( element );

API

var tapper = new TapListener( element )
// element {Element} - binds tap events to element

tapper.bindTap( element )
// element {Element} - binds tap events to element

tapper.unbindTap()
// unbinds tap events

tapper.on( eventName, callback )
// eventName {String} - tap, pointerDown, pointerMove, pointerUp, pointerCancel
// callback {Function}

function callback( event, pointer ) {...}
// event {Event} - the original mouseup, touchend, or pointerup event
// pointer {Event} or {Touch} - event object with pageX and pageY

tapper.destroy()
// unbinds tap events

MIT license

By Metafizzy