useSwipe
Reactive swipe detection based on TouchEvents
.
Demo
Direction: NONE
lengthX: 0 | lengthY: 0
Usage
<template>
<div ref="el">
Swipe here
</div>
</template>
<script>
setup() {
const el = ref(null)
const { isSwiping, direction } = useSwipe(el)
return { el, isSwiping, direction }
}
</script>
<template>
<div ref="el">
Swipe here
</div>
</template>
<script>
setup() {
const el = ref(null)
const { isSwiping, direction } = useSwipe(el)
return { el, isSwiping, direction }
}
</script>
Type Declarations
Show Type Declarations
export declare enum SwipeDirection {
UP = "UP",
RIGHT = "RIGHT",
DOWN = "DOWN",
LEFT = "LEFT",
NONE = "NONE",
}
export interface SwipeOptions extends ConfigurableWindow {
/**
* Register events as passive
*
* @default true
*/
passive?: boolean
/**
* @default 50
*/
threshold?: number
/**
* Callback on swipe start
*/
onSwipeStart?: (e: TouchEvent) => void
/**
* Callback on swipe moves
*/
onSwipe?: (e: TouchEvent) => void
/**
* Callback on swipe ends
*/
onSwipeEnd?: (e: TouchEvent, direction: SwipeDirection) => void
}
export interface SwipeReturn {
isPassiveEventSupported: boolean
isSwiping: Ref<boolean>
direction: ComputedRef<SwipeDirection | null>
coordsStart: Readonly<Position>
coordsEnd: Readonly<Position>
lengthX: ComputedRef<number>
lengthY: ComputedRef<number>
stop: () => void
}
/**
* Reactive swipe detection.
*
* @see https://vueuse.org/useSwipe
* @param target
* @param options
*/
export declare function useSwipe(
target: MaybeRef<EventTarget | null | undefined>,
options?: SwipeOptions
): SwipeReturn
export declare enum SwipeDirection {
UP = "UP",
RIGHT = "RIGHT",
DOWN = "DOWN",
LEFT = "LEFT",
NONE = "NONE",
}
export interface SwipeOptions extends ConfigurableWindow {
/**
* Register events as passive
*
* @default true
*/
passive?: boolean
/**
* @default 50
*/
threshold?: number
/**
* Callback on swipe start
*/
onSwipeStart?: (e: TouchEvent) => void
/**
* Callback on swipe moves
*/
onSwipe?: (e: TouchEvent) => void
/**
* Callback on swipe ends
*/
onSwipeEnd?: (e: TouchEvent, direction: SwipeDirection) => void
}
export interface SwipeReturn {
isPassiveEventSupported: boolean
isSwiping: Ref<boolean>
direction: ComputedRef<SwipeDirection | null>
coordsStart: Readonly<Position>
coordsEnd: Readonly<Position>
lengthX: ComputedRef<number>
lengthY: ComputedRef<number>
stop: () => void
}
/**
* Reactive swipe detection.
*
* @see https://vueuse.org/useSwipe
* @param target
* @param options
*/
export declare function useSwipe(
target: MaybeRef<EventTarget | null | undefined>,
options?: SwipeOptions
): SwipeReturn