Skip to content

A javascript module for handling mobile device touches

Notifications You must be signed in to change notification settings

nathkrill/Touch-Handler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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!

About

A javascript module for handling mobile device touches

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published