Skip to content

Easily detect swiping motions and taps with customization event functions.

License

Notifications You must be signed in to change notification settings

BulmerCloud/Gesture-Control

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

Gesture-Control

Description:

This script allows you to easily detect swipes of all four directions and on tap.

How to use:

To use this script, add the following HTML anywhere inside of your code and use the given Javascript code to add your own 'on swipe' and 'on tap' functions.

HTML:

<script type="text/javascript" src="touch.js" />

Javascript

let myElement = document.getElementById('myDiv');

const touch = new TouchInput(myElement, {
    // Options:
    treshold: 10, // this is 10% of the page's width; default is 1%.
    
    // Events:              (these are also the default event handlers)
    onSwipeLeft: (event) => {
        console.log('Swiped left');
    },
    onSwipeRight: (event) => {
        console.log('Swiped right');
    },
    onSwipeUp: (event) => {
        console.log('Swiped up');
    },
    onSwipeDown: (event) => {
        console.log('Swiped down');
    },
    onTap: (event) => {
        console.log('Tap');
    }
});

About

Easily detect swiping motions and taps with customization event functions.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published