Home

Awesome

Tap Event

Make your touchstart event listeners into a tap event listener!

What is "correct" behavior? The tap event:

API

var tap = require('tap-event')

var el = document.querySelector('#container')

// the event you want to handle
function changeLocation(e) {
  // e.preventDefault() is already called!
  location.href = this.href
}

// wrap the listener
var listener = tap(changeLocation)

// listen to `touchstart`
el.addEventListener('touchstart', listener)

// remove the listener
el.removeEventListener('touchstart', listener)

or, more succinctly:

document.querySelector('#container').addEventListener('touchstart', tap(function (e) {
  location.href = this.href
}))

To set a custom timeout (default is 200ms), you have two options:

// set globally
tap.timeout = 300

// set per instance
tap(function (e) {

}, {
  timeout: 300
})