An open API service indexing awesome lists of open source software.

https://github.com/a145789/vtouchdir

vue3 custom direction for mobile development using the touch api, get the direction of slide.
https://github.com/a145789/vtouchdir

directions directive touch vue vue-directive vue3

Last synced: 7 months ago
JSON representation

vue3 custom direction for mobile development using the touch api, get the direction of slide.

Awesome Lists containing this project

README

          


NPM Version
NPM Downloads
License


中文

# vtouchdir

A mobile vue3 touch api custom directive for swipe direction

## Installation

### npm

```bash
npm install --save-dev vtouchdir
```

### pnpm

```bash
pnpm add vtouchdir -D
```

## Docs

### touchDir

**Description**

A function can be passed in, which will be called after the element slides, and can receive three parameters.

**Usage**

```vue

import vTouchdir from "vtouchdir"

const handler = (
direction: Direction,
e: TouchEvent,
rangeParams: {
startPageX: number
startPageY: number
endPageX: number
endPageY: number
deltaX: number
deltaY: number
}
) => {}

```

Supports the same [event modifiers](https://v3.vuejs.org/guide/essentials/event-handling.html#event-modifiers) as `vue` except for `passive`, `.self` has the highest priority

```vue

import vTouchdir from "vtouchdir"

function handler(dir: "left" | "right" | "up" | "down") {}

```

The default swipe range is **10**, and the `handler` will be triggered only when the swipe exceeds **10**. You can specify a `range` parameter to customize the range

```vue

import vTouchdir from "vtouchdir"

function handler(dir: "left" | "right" | "up" | "down") {}

```

**Typescript**

If you use `ts`, you can export the `Direction` enum

```ts
// vtouchdir
export enum Direction {
LEFT = "left",
RIGHT = "right",
UP = "up",
DOWN = "down",
}

// use
import vTouchdir, { Direction } from "vtouchdir"
```