touch-handler
v1.0.2
Published
Allow for easier touch interaction handling
Downloads
14
Maintainers
Readme
Touch Handler
A simple library to handle touches and swipes using Javascript.
Usage
Include touch-handler.js
in your project.
import TouchHandler from '/path/to/src/touch-handler.js';
const element = document.querySelector('.touch');
new TouchHandler(element, {
touchStart: startFunction, // Code that will run when a touch starts
touchMove: moveFunction, // Code that will run when a touch is moving <-- This is where the magic happens for me!
touchEnd: endFunction // Code that will run when the touch is ended or cancelled.
});
OR, include the built js:
<script src='/path/to/dist/touch-handler.js'></script>
Inside each of your functions you can use this
to access the TouchHandler instance.
Useful things in there are:
this.currentTouch; // An object with x & y co-ordinates of the current touch point (available in touchMove and touchEnd)
this.startTouch; // An object with x & y co-ordinates of the start touch. (available in any of the three methods)
And that's it!