Touch Events with ease
npm install tocada
/**
Add events for
swipe // fired before swipeleft, up, down, right events
swipeup
swiperight
swipedown
swipeleft
gesture // fired before any pinch or spread
pinch
spread
*/
import { useTouchEvents } from "tocada";
const swipeArea = useTouchEvents(querySelector | element);
/**
Remove events
*/
swipeArea.destroy();
The above CustomEvent
s emit a detail
object with the following data
velocityX, // speed of x-axis movement
velocityY, // speed of y-axis movement
velocity, // speed of overall touch event
avgPressure, // touch pressure for the entire event
startPressure, // starting touch pressure for the event
endPressure, // ending touch pressure for the event
startTime, // datetime at the start of the event
endTime, // datetime at the end of the event
distanceX, // distance traveled over the x-axis
distanceY, // distance traveled over the y-axis
distance, // distance traveled in a straight line
startingElement,// first element touched
endingElement, // last element touched
touchedElements,// all of the element (including duplicates) touched during the event -- convert to a Set to make elements unique: new Set(touchedElements);
I write a lot of open source software (some more useful than others). You can help me out by tossing me a few bucks to buy coffee.