跳到主要内容

usePointerSwipe

分类
导出大小
1.33 kB
上次更改
6 个月前

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

演示

用法

vue
<script setup lang="ts">
import { 
usePointerSwipe
} from '@vueuse/core'
import {
useTemplateRef
} from 'vue'
const
el
=
useTemplateRef
('el')
const {
isSwiping
,
direction
} =
usePointerSwipe
(
el
)
</script> <template> <
div
ref
="
el
">
Swipe here </
div
>
</template>

类型声明

显示类型声明
ts
export interface UsePointerSwipeOptions {
  /**
   * @default 50
   */
  
threshold
?: number
/** * Callback on swipe start. */
onSwipeStart
?: (
e
: PointerEvent) => void
/** * Callback on swipe move. */
onSwipe
?: (
e
: PointerEvent) => void
/** * Callback on swipe end. */
onSwipeEnd
?: (
e
: PointerEvent,
direction
:
UseSwipeDirection
) => void
/** * Pointer types to listen to. * * @default ['mouse', 'touch', 'pen'] */
pointerTypes
?:
PointerType
[]
/** * Disable text selection on swipe. * * @default false */
disableTextSelect
?: boolean
} export interface UsePointerSwipeReturn { readonly
isSwiping
:
ShallowRef
<boolean>
direction
:
Readonly
<
ShallowRef
<
UseSwipeDirection
>>
readonly
posStart
:
Position
readonly
posEnd
:
Position
distanceX
:
Readonly
<
ComputedRef
<number>>
distanceY
:
Readonly
<
ComputedRef
<number>>
stop
: () => void
} /** * Reactive swipe detection based on PointerEvents. * * @see https://vueuse.org.cn/usePointerSwipe * @param target * @param options */ export declare function
usePointerSwipe
(
target
:
MaybeRefOrGetter
<HTMLElement | null | undefined>,
options
?: UsePointerSwipeOptions,
): UsePointerSwipeReturn

来源

源代码演示文档

贡献者

Anthony Fu
IlyaL
Anthony Fu
Jeffrey Li
SerKo
2nofa11
Fernando Fernández
Mohammad Amin Mokhtari
Alexey Istomin
丶远方
Curt Grimes
sun0day
Jelf
wheat
MinatoHikari
Ilya Komichev
lstoeferle

更新日志

v13.2.0
d3ed6 - fix: 允许在 usePointerSwipe 中垂直滚动 (#4637) (#4720)
v12.8.0
7432f - feat(types): 废弃 MaybeRefMaybeRefOrGetter,转而使用 Vue 的原生类型 (#4636)
v12.4.0
dd316 - feat: 尽可能在所有地方使用被动事件处理程序 (#4477)
0a9ed - feat!: 放弃对 Vue 2 的支持,优化打包并清理 (#4349)
v10.7.0
fd67b - feat: 添加 disableTextSelect 选项 (#3604)

根据 MIT 许可证发布。