Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/wobsoriano/svelte-gesture

👇 Bread n butter utility for component-tied mouse/touch gestures in Svelte.
https://github.com/wobsoriano/svelte-gesture

directive drag gestures pinch scroll svelte wheel zoom

Last synced: 22 days ago
JSON representation

👇 Bread n butter utility for component-tied mouse/touch gestures in Svelte.

Awesome Lists containing this project

README

        

# svelte-gesture

[![npm (tag)](https://img.shields.io/npm/v/svelte-gesture?style=flat&colorA=000000&colorB=000000)](https://www.npmjs.com/package/svelte-gesture) ![npm bundle size](https://img.shields.io/bundlephobia/minzip/svelte-gesture?style=flat&colorA=000000&colorB=000000) ![NPM](https://img.shields.io/npm/l/svelte-gesture?style=flat&colorA=000000&colorB=000000)

svelte-gesture is a library that lets you bind richer mouse and touch events to any component or view. With the data you receive, it becomes trivial to set up gestures, and often takes no more than a few lines of code.

Each recognizer is implemented as an action that emits custom events. To make the most of it you should combine it with Svelte's [spring](https://svelte.dev/tutorial/spring) function.

## Installation

```bash
npm install svelte-gesture
```

To get TypeScript working, add `svelte-gesture/globals` to the `types` field in your `tsconfig.json`

```json
{
"compilerOptions": {
"types": ["svelte-gesture/globals"]
}
}
```

## Usage

```html

import { spring } from 'svelte/motion';
import { drag } from 'svelte-gesture';

let coords = spring({ x: 0, y: 0 });

function handler({ detail }) {
const {
active,
movement: [mx, my]
} = detail;

coords.set({
x: active ? mx : 0,
y: active ? my : 0
});
}


```

### Simple example



More examples soon...

## Actions

svelte-gesture exports several actions that can handle different gestures.

| Action | Description |
| -------- | ------------------------------------------ |
| `drag` | Handles the drag gesture |
| `move` | Handles mouse move events |
| `hover` | Handles mouse enter and mouse leave events |
| `scroll` | Handles scroll events |
| `wheel` | Handles wheel events |
| `pinch` | Handles the pinch gesture |

## License

MIT