# on-swipe

> Adds a swipe event to the DOM that reports direction, velocity, distance, and duration on touch devices

Latest version **1.0.9** (published 2020-05-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install on-swipe
pnpm add on-swipe
yarn add on-swipe
bun add on-swipe
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.9 |
| Published | 2020-05-01 |
| First published | 2019-08-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 7.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Ron Gruesbeck |
| Maintainers | rongruesbeck |
| Keywords | mobile, swipe, touch, gesture, event, direction, velocity, distance, duration, speed |

## Links

- npm: https://www.npmjs.com/package/on-swipe
- Repository: https://github.com/rgruesbeck/on-swipe
- Homepage: https://github.com/rgruesbeck/on-swipe#readme
- Issues: https://github.com/rgruesbeck/on-swipe/issues
- npm.io page: https://npm.io/package/on-swipe

## Alternatives

- [async-exit-hook](https://npm.io/package/async-exit-hook.md) — 3.7M weekly downloads
- [evnty](https://npm.io/package/evnty.md) — 7.2K weekly downloads
- [eleventy-plugin-asciidoc](https://npm.io/package/eleventy-plugin-asciidoc.md) — 3.5K weekly downloads
- [@jswork/next-get2get](https://npm.io/package/@jswork/next-get2get.md) — 945 weekly downloads
- [@dashersw/axon](https://npm.io/package/@dashersw/axon.md) — 934 weekly downloads

## Recent versions

- 1.0.9 (latest) — 2020-05-01
- 1.0.8 — 2019-10-26
- 1.0.7 — 2019-10-26
- 1.0.6 — 2019-08-05
- 1.0.5 — 2019-08-01
- 1.0.4 — 2019-08-01
- 1.0.3 — 2019-08-01
- 1.0.2 — 2019-08-01
- 1.0.1 — 2019-08-01

## README

# on-swipe
Adds a swipe event do the DOM that reports direction, velocity, distance, and duration.

## tldr;
```js
import onSwipe from 'on-swipe';

// register swipe event emitter
onSwipe();

// listen for swipe event
document.addEventListener('swipe', (event) => {

    // use swipe
    console.log(event.detail);
})
```

## Install
```sh
npm install --save on-swipe
```

## Use
Call `onSwipe()` once after your app loads.

### Syntax
```js 
onSwipe({options})
```
* `options` is an object with the following optional properties:
  + `node: document` DOM node you want to broadcast the swipe event from.
  + `sensitivity: 5` number of touch moves before emitting a swipe event.
  + `bubbles: true` if the event should bubble.
  + `cancelable: true` if the `event.preventDefault()` should work.

### Returns
The swipe events `event.detail` attribute contains the following properties:

| Variable | Type | Description |
|----------|------|-------------|
| `direction`   | `string` | The direction of the swipe in [left, right, up, down]|
| `velocity` | `float` | velocity of swipe in pixels/millisecond |
| `distance` | `float` | distance of swipe in pixels |
| `duration` | `int` | duration of swipe in milliseconds |
| `dx` | `float` | distance of swipe x direction |
| `dy` | `float` | distance of swipe y direction |

### Examples
#### Default

```js
import onSwipe from 'on-swipe';

// register swipe event emitter
onSwipe();

// listen for swipe event
document.addEventListener('swipe', (event) => {

    // use swipe
    let { direction, velocity, distance, duration } = event.detail;
})
```

#### Options

```js
import onSwipe from 'on-swipe';

// register swipe event emitter
onSwipe({ node: window, sensitivity: 10 });

// listen for swipe event
window.addEventListener('swipe', (event) => {

    // use swipe
    let { direction, velocity, distance, duration } = event.detail;
})
```

---
_Source: https://npm.io/package/on-swipe · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
