usePointerSwipe
基于 PointerEvents 的响应式滑动检测。
Demo
滑动
用法
vue
<script setup>
import { usePointerSwipe } from '@vueuse/core'
import { ref } from 'vue'
const el = ref(null)
const { isSwiping, direction } = usePointerSwipe(el)
</script>
<template>
<div ref="el">
在此处滑动
</div>
</template>
类型声明
显示类型声明
typescript
export interface UsePointerSwipeOptions {
/**
* @default 50
* 阈值
*/
threshold?: number
/**
* 滑动开始时的回调。
*/
onSwipeStart?: (e: PointerEvent) => void
/**
* 滑动移动时的回调。
*/
onSwipe?: (e: PointerEvent) => void
/**
* 滑动结束时的回调。
*/
onSwipeEnd?: (e: PointerEvent, direction: UseSwipeDirection) => void
/**
* 要监听的指针类型。
*
* @default ['mouse', 'touch', 'pen']
*/
pointerTypes?: PointerType[]
/**
* 在滑动时禁用文本选择。
*
* @default false
*/
disableTextSelect?: boolean
}
export interface UsePointerSwipeReturn {
readonly isSwiping: Ref<boolean>
direction: Readonly<Ref<UseSwipeDirection>>
readonly posStart: Position
readonly posEnd: Position
distanceX: Readonly<Ref<number>>
distanceY: Readonly<Ref<number>>
stop: () => void
}
/**
* 基于 PointerEvents 的响应式滑动检测。
*
* @see https://vueuse.org/usePointerSwipe
* @param target
* @param options
*/
export declare function usePointerSwipe(
target: MaybeRefOrGetter<HTMLElement | null | undefined>,
options?: UsePointerSwipeOptions,
): UsePointerSwipeReturn
Source
贡献者
Anthony Fu
丶远方
Jeffrey Li
Anthony Fu
Mohammad Amin Mokhtari
Alexey Istomin
Curt Grimes
sun0day
Jelf
wheat
MinatoHikari
Ilya Komichev
lstoeferle
变更日志
v10.7.0
on 12/5/2023v10.0.0-beta.4
on 4/13/20234d757
- feat(types)!: rename MaybeComputedRef
to MaybeRefOrGetter
10e98
- feat(toRef)!: rename resolveRef
to toRef
v10.0.0-beta.0
on 3/14/2023f285c
- fix(useSwipe)!: use literal for swipe direction instead of enumv9.5.0
on 11/9/2022