Tocca.js
Super lightweight script ( ~1kB ) to detect via Javascript events like 'tap' 'longtap' 'dbltap' 'swipeup' 'swipedown' 'swipeleft' 'swiperight' on any kind of device.
Donations
If this project helped getting your job done consider making a donation for all the time I spend to bring it to you
Installation
Npm
$ npm install tocca
Bower
$ bower install Tocca.js -save
Usage
Include the script into your page:
Once you have included Tocca.js you will be able to catch all the new events:
elm;elm;elm;elm;elm;elm;elm;
It works with jQuery as well:
;;;;;;;
Tocca.js supports also the inline events if you are using Riot.js!
API and Examples
Anytime you will use a Tocca.js event the callback function will receive a special event object containing the following properties
x
{ Int }: latest x position of pointer at the end of the eventy
{ Int }: latest y position of pointer at the end of the eventoriginalEvent
{ Object }: the original javascript native event that has been triggereddistance
: this property is available only for the swipe eventsx
{ Int }: the x absolute difference between the beginning and the end of the swipe gesturey
{ Int }: the y absolute difference between the beginning and the end of the swipe gesture
Examples:
elm;elm;// with jQuery;;
Anyway you can combine Tocca.js with the default javascript touch events:
touchmove
touchstart
touchend
touchcancel
To disable the default touch behaviours (zoom on double tap, scroll on swipe...) on a certain element via javascript you can always use the following snippet:
elm;elm;elm;
Configuration
Whenever you want to configure the plugin events settings you can do that simply specifying two constants before including Tocca.js into the page
In Tocca.js 1.1.0 you can also configure/get the internal options via function:
window console // will always return the current internal options
Browser Support
Actually the script has been tested on all the modern browsers but it need a better testing phase over several platforms: Chrome 29+ Firefox 23+ Opera 12+ Safari 5+
It works on mobile/tablet browsers and on desktop browsers as well.
On the old browsers all the Tocca.js events cannot be triggered.
Changelog
2.0.9
- fixed: removed
const
variables
2.0.8
- fixed: 70
2.0.7
- fixed: 69
2.0.6
- update: improve multiple touches events detection
2.0.5
- fixed: #65
2.0.4
- fixed: #62
2.0.3
- fixed: #51 #54
- fixed: the PointerUp event is not always dispatched on Chrome and Android devices, prioritize always the
touch*
overpointer*
events
2.0.1
2.0.0
- fixed: https://github.com/GianlucaGuarini/Tocca.js/issues/44
- added: support for the new
pointerevents
1.1.0
- added: the possibility to configure via function the internal tocca options
- added: the
IGNORE_JQUERY
option
1.0.1
1.0.0
Thanks to @AndyOGo for his help on this release
- fixed: #34 #35
- fixed: more reliable and performant events on the hybrid devices
- fixed: multiple events dispatched on
tap
0.2.0
- added:
longtap
event and theLONG_TAP_THRESHOLD
variable - fixed: inconsistencies and issues across the hybrid devices
0.1.7
- added:
longtap
event and theLONG_TAP_THRESHOLD
variable
0.1.5
- added: support for the inline events
0.1.4
- fixed:
dbltap
https://github.com/GianlucaGuarini/Tocca.js/pull/16 - updated: node devDependecies updated
0.1.3
- fixed:
dbltap
issue https://github.com/GianlucaGuarini/Tocca.js/issues/14
0.1.2
- updated: no more deferred
tap
events, atap
event gets triggered immediately if it's in theTAP_THRESHOLD
time range - updated: a
tap
event will always come first adbltap
event
0.1.1
- updated: better and faster tap events detection
- updated: node devDependecies updated
- added: DBL_TAP_THRESHOLD option
0.1.0
- bugfix: optimizing the support for the microsoft hybrid devices (IE10/IE11)
0.0.8
- 'touchcancel' event removed to fix and android issue on page scroll
0.0.7
- nothing important (just a workaround to fix the tests on the motherfucker Phantomjs)
0.0.6
- bugfix: do not set the mouse event listeners on any touch device and vice versa
- added: new JUST_ON_TOUCH_DEVICES option to block all the Tocca.js events on the no-touch devices
0.0.5
- tap precision option included
0.0.4
dpltap
renameddbltap
- new demo added demo-fun.html
0.0.3
- Tests added
0.0.2
- Android Bug fix
What does Tocca mean?!
'Tocca' is the second person singular of the imperative Italian verb 'Toccare' that means to touch.