vanilla-swipe
Tiny vanilla JS library to detect swipe direction.
Types
type ConstructorProps = {
element?: HTMLElement | null;
rotationAngle?: number | 0;
delta?: number | 10;
mouseTrackingEnabled?: boolean | false;
touchTrackingEnabled?: boolean | true;
preventDefaultTouchmoveEvent?: boolean | false;
onSwiping?: EventHandler;
onSwiped?: EventHandler;
onTap?: (e: Event) => void;
};
type EventHandler = {
(
e: Event,
deltaX: number,
deltaY: number,
absX: number,
absY: number,
duration: number,
velocity: number
): void;
};
Methods
init(): void
update(options: ConstructorProps): void
destroy(): void
Install
npm install vanilla-swipe
Examples
import VanillaSwipe from 'vanilla-swipe';
const VS = new VanillaSwipe({
element: document.getElementById('some-id');
onSwiping: handler,
onSwiped: handler,
mouseTrackingEnabled: true,
});
VS.init();
function handler() {
console.log(...arguments);
}
Tests
npm test
Coverage
npm run testWithCoverage