component-tap-event
Create tap event listeners
Last updated 4 years ago by chemzqm .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install component-tap-event 
SYNC missed versions from official npm registry.

Tap Event

Build Status

Make your touchstart event listeners into a tap event listener!

What is "correct" behavior? The tap event:

  • shouldn't be triggered until the user removes his/her finger from the surface of the screen.
  • shouldn't be triggered when the user moves his/her finger at all (ie it should not interfere with drag events).
  • shouldn't be triggered if there's ever more than a single finger on the surface at all.
  • should never trigger the click event.

Preserve context and arguments in 1.1.0, works with delegate easily

Install

npm install component-tap-event -S

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
})

Current Tags

  • 1.1.4                                ...           latest (4 years ago)

6 Versions

  • 1.1.4                                ...           4 years ago
  • 1.1.3                                ...           5 years ago
  • 1.1.2                                ...           5 years ago
  • 1.1.1                                ...           5 years ago
  • 1.1.0                                ...           5 years ago
  • 1.0.0                                ...           5 years ago
Maintainers (1)
Downloads
Today 0
This Week 7
This Month 43
Last Day 3
Last Week 16
Last Month 76
Dependencies (0)
None
Dev Dependencies (16)

Copyright 2014 - 2016 © taobao.org |