fn
useSwipe
v0.0.15testeddemoDetect swipe gestures via touch events on a target element. Tracks start/end coordinates, the active state and the resolved direction.
Example
ts
const el = useTemplateRef<HTMLElement>('el');
const { isSwiping, direction, lengthX, lengthY } = useSwipe(el, {
onSwipeEnd(e, dir) { console.log(dir); },
});Demo
Loading demo…
Signature
ts
export function useSwipe(
target: MaybeComputedElementRef,
options: UseSwipeOptions ={ ... }Parameters
| Parameter | Type | Description |
|---|---|---|
target | MaybeComputedElementRef | Element ref, getter, or instance to listen on |
options? | UseSwipeOptions | Threshold, lifecycle callbacks and passive flag |
Returns
UseSwipeReturnReactive swipe state and a `stop` teardown function