Skip to content

usePointerSwipe

Category
Export Size
1.33 kB
Last Changed
4 days ago

Reactive swipe detection based on PointerEvents.

Demo

Usage

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>

Type Declarations

Show Type Declarations
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/usePointerSwipe * @param target * @param options */ export declare function
usePointerSwipe
(
target
:
MaybeRefOrGetter
<HTMLElement | null | undefined>,
options
?: UsePointerSwipeOptions,
): UsePointerSwipeReturn

Source

SourceDemoDocs

Contributors

NoiseFan

Changelog

No recent changes

Released under the MIT License.