Skip to content

usePointerSwipe

类别
导出体积
1.24 kB
上次更改
3 days ago

基于 PointerEvents 的响应式滑动检测。

示例

滑动

用法

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

源码

源码演示文档

贡献者

Anthony Fu
一纸忘忧
Jeffrey Li
Fernando Fernández
Anthony Fu
Mohammad Amin Mokhtari
Alexey Istomin
丶远方
Curt Grimes
sun0day
Jelf
wheat
MinatoHikari
Ilya Komichev
lstoeferle

更新日志

v12.4.0 on 1/10/2025
dd316 - feat: use passive event handlers everywhere is possible (#4477)
v12.0.0-beta.1 on 11/21/2024
0a9ed - feat!: drop Vue 2 support, optimize bundles and clean up (#4349)
v10.7.0 on 12/5/2023
fd67b - feat: add disableTextSelect option (#3604)
v10.0.0-beta.4 on 4/13/2023
4d757 - feat(types)!: rename MaybeComputedRef to MaybeRefOrGetter
10e98 - feat(toRef)!: rename resolveRef to toRef
v10.0.0-beta.0 on 3/14/2023
f285c - fix(useSwipe)!: use literal for swipe direction instead of enum
08c21 - feat(useSwipe, usePointerSwipe, useTransition): improve tree-shaking (#2863)