0.1.4 • Published 2 months ago

svelte-gesture v0.1.4

Weekly downloads
-
License
-
Repository
-
Last release
2 months ago

svelte-gesture

npm (tag) npm bundle size NPM

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 function.

Installation

npm install svelte-gesture

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

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

Usage

<script>
	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
		});
	}
</script>

<div use:drag on:drag="{handler}" style:transform="translate({$coords.x}px, {$coords.y}px)" />

Simple example

More examples soon...

Actions

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

ActionDescription
dragHandles the drag gesture
moveHandles mouse move events
hoverHandles mouse enter and mouse leave events
scrollHandles scroll events
wheelHandles wheel events
pinchHandles the pinch gesture

License

MIT

0.1.4

2 months ago

0.1.3

1 year ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago

0.0.1

2 years ago