ag-swipe-core
v1.0.2
Published
A lightweight library to detect swipes on touchscreen devices.
Downloads
1,770
Maintainers
Readme
For more details on the public interface of the library please see the Github page.
Installation
npm install ag-swipe-core --save
Usage
import { createSwipeSubscription, SwipeEvent } from 'ag-swipe-core';
const domElement: HTMLElement = document.querySelector('#swipe-element');
const swipeSubscription = createSwipeSubscription({
domElement,
onSwipeEnd: (event: SwipeEvent) => {
console.log(`SwipeEnd direction: ${event.direction} and distance: ${event.distance}`);
},
});
Unsubscribing
When swipe events should no longer be tracked:
if (swipeSubscription) {
swipeSubscription.unsubscribe();
}