Socket
Socket
Sign inDemoInstall

svelte-gesture

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

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=0


Version published
Weekly downloads
122
increased by3.39%
Maintainers
1
Weekly downloads
 
Created
Source

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

FAQs

Package last updated on 29 Feb 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc