Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/component/tap-event
Create tap event listeners
https://github.com/component/tap-event
Last synced: 12 days ago
JSON representation
Create tap event listeners
- Host: GitHub
- URL: https://github.com/component/tap-event
- Owner: component
- License: mit
- Created: 2013-11-24T16:43:39.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2015-11-13T20:04:54.000Z (about 9 years ago)
- Last Synced: 2024-12-12T01:10:28.083Z (16 days ago)
- Language: JavaScript
- Size: 157 KB
- Stars: 17
- Watchers: 2
- Forks: 5
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Tap Event
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.## API
```js
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:
```js
document.querySelector('#container').addEventListener('touchstart', tap(function (e) {
location.href = this.href
}))
```To set a custom timeout (default is `200ms`), you have two options:
```js
// set globally
tap.timeout = 300// set per instance
tap(function (e) {}, {
timeout: 300
})
```