1.0.2 • Published 4 years ago

touch-handler v1.0.2

Weekly downloads
1
License
ISC
Repository
github
Last release
4 years ago

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!