useSwipe
基于 TouchEvents
的响应式滑动检测。
Demo
方向:none
水平长度:0 | 垂直长度:0
用法
vue
<script setup>
const el = ref(null)
const { isSwiping, direction } = useSwipe(el)
</script>
<template>
<div ref="el">
在这里滑动
</div>
</template>
类型声明
显示类型声明
typescript
export type UseSwipeDirection = "up" | "down" | "left" | "right" | "none"
export interface UseSwipeOptions extends ConfigurableWindow {
/**
* 将事件注册为被动事件
*
* @default true
*/
passive?: boolean
/**
* @default 50
*/
threshold?: number
/**
* 滑动开始时的回调函数
*/
onSwipeStart?: (e: TouchEvent) => void
/**
* 滑动过程中的回调函数
*/
onSwipe?: (e: TouchEvent) => void
/**
* 滑动结束时的回调函数
*/
onSwipeEnd?: (e: TouchEvent, direction: UseSwipeDirection) => void
}
export interface UseSwipeReturn {
isPassiveEventSupported: boolean
isSwiping: Ref<boolean>
direction: ComputedRef<UseSwipeDirection>
coordsStart: Readonly<Position>
coordsEnd: Readonly<Position>
lengthX: ComputedRef<number>
lengthY: ComputedRef<number>
stop: () => void
}
/**
* 响应式滑动检测。
*
* @see https://vueuse.org/useSwipe
* @param target
* @param options
*/
export declare function useSwipe(
target: MaybeRefOrGetter<EventTarget | null | undefined>,
options?: UseSwipeOptions,
): UseSwipeReturn
Source
贡献者
Anthony Fu
丶远方
Amirreza Zarkesh
lstoeferle
Anthony Fu
Alexey Istomin
Jelf
云游君
Shinigami
Alex Kozack
变更日志
v10.7.0
on 12/5/2023v10.1.0
on 4/22/2023v10.0.0-beta.4
on 4/13/20234d757
- feat(types)!: rename MaybeComputedRef
to MaybeRefOrGetter
v10.0.0-beta.0
on 3/14/2023f285c
- fix!: use literal for swipe direction instead of enum