TouchSweep
Super tiny vanilla JS module to detect swipe direction and trigger custom events accordingly.
This module works on touch-enabled devices only.
Install
npm i touchsweep
or
yarn add touchsweep
or
just download this repository and use the files located in dist
folder.
Usage
import TouchSweep from 'touchsweep';
const area = document.getElementById('swipe-area');
const data = {
value: 1
};
const touchThreshold = 20;
new TouchSweep(area, data, touchThreshold);
area.addEventListener('swipeleft', event => {
});
area.addEventListener('swiperight', event => {
});
area.addEventListener('swipedown', event => {
});
area.addEventListener('swipeup', event => {
});
area.addEventListener('tap', event => {
});
Options and default settings
The module constructor accepts three (3) arguments:
element
: A HTML Element. Default is document.body
eventData
: A plain JS object. Default is {}
threshold
: How many pixels to count until an event is fired. Default is 40
Supported Browsers
Currently all evergreen browsers are supported.
IE 10+ support is planned in the near future.
Demo
There is a simple demo illustrating how the TouchSweep library works.
Check it out here
LICENSE
MIT