touchy
Yet another tap
, tap:hold
and swipe
events enabler. Based on
xtap-event/tap.js
TODO: Add unit tests
installation
npm i --save touchy
usage
// usually this is enough to generate the events// this can be done in a module that can be required// at the beginning of your app to generate the eventsvar touchy = ;touchy;
Events
This library will generate the following events:
tap
tap:hold
swipe
swipe:up
swipe:down
swipe:left
swipe:right
tap
The tap
event is generated when:
- a
touchstart
/mousedown
event is followed by atouchend
/mouseup
- the
end target
is the same as thestart target
- the user hasn't move the finger between the starting event and the end
event for more than
options.minTapDisplacementTolerance
(default: 10px) - the time between
touchstart
/mousedown
andtouchend
/mouseup
is less thanopts.tapHoldMinThreshold
(default: 500ms)
Example
// usually this is enough to generate the eventsvar touchy = ;touchy; var ele = document;ele;
tap:hold
The tap:hold
event is generated when:
- a
touchstart
/mousedown
event is followed by atouchend
/mouseup
- the
end target
is the same as thestart target
- the user hasn't move the finger between the starting event and the end
event for more than
options.minTapDisplacementTolerance
(default: 10px) - the user has not released the finger for more than
opts.tapHoldMinThreshold
(default: 500ms)
Example
// usually this is enough to generate the eventsvar touchy = ;touchy; var ele = document;ele;
swipe, swipe:left, swipe:right, swipe:up and swipe:down
The swipe
event is generated when
- a
touchstart
/mousedown
event is followed bytouchmove
/mousemove
and then by atouchend
/mouseup
- the user has moved the finger between the starting event and the end
event for more than
options.minTapDisplacementTolerance
(default: 10px) - a
tap:hold
event has not being generated
Example
// usually this is enough to generate the eventsvar touchy = ;touchy; var ele = document;ele;
Custom events are also generated with the direction of the swipe: swipe:left
, swipe:right
, swipe:up
and swipe:down
// usually this is enough to generate the eventsvar touchy = ;touchy; var ele = document;ele;