Skip to content

usePointerSwipe ​

Category
Export Size
1.04 kB
Last Changed
2 months ago

Reactive swipe detection based on PointerEvents.

Demo ​

Swipe

Usage ​

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">
    Swipe here
  </div>
</template>

Type Declarations ​

Show Type Declarations
typescript
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: Ref<boolean>
  direction: Readonly<Ref<UseSwipeDirection>>
  readonly posStart: Position
  readonly posEnd: Position
  distanceX: Readonly<Ref<number>>
  distanceY: Readonly<Ref<number>>
  stop: () => void
}
/**
 * Reactive swipe detection based on PointerEvents.
 *
 * @see https://vueuse.org/usePointerSwipe
 * @param target
 * @param options
 */
export declare function usePointerSwipe(
  target: MaybeRefOrGetter<HTMLElement | null | undefined>,
  options?: UsePointerSwipeOptions,
): UsePointerSwipeReturn

Source ​

Source • Demo • Docs

Contributors ​

Anthony Fu
Jeffrey Li
Anthony Fu
Mohammad Amin Mokhtari
Alexey Istomin
丶远方
Curt Grimes
sun0day
Jelf
wheat
MinatoHikari
Ilya Komichev
lstoeferle

Changelog ​

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)
v9.5.0 on 11/9/2022
862d1 - fix: handle secondary clicks properly (#2379)

Released under the MIT License.