touch-handler

1.0.2 • Public • Published

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!

Package Sidebar

Install

npm i touch-handler

Weekly Downloads

4

Version

1.0.2

License

ISC

Unpacked Size

11.4 kB

Total Files

9

Last publish

Collaborators

  • nathkrill