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

Overview

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.

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

You might also like...

Svelte component to render markdown.

svelte-exmarkdown Svelte component to render markdown. Motivation svelte-markdown is a good component package. However, it is not extensible. You cann

Jan 6, 2023

A ✨light✨ and magical Svelte component for CSS media queries🐹

Svelte CSS media queries 🐥 Demo - Svelte REPL Lightweight, comfortable, like Svelte 🐣 how to install npm i svelte-media-queries What can I do? quer

Dec 26, 2022

Svelte component to display time distances in a human readable format.

Time Distance Display time distances in a human readable format. Based on date-fns Updates every 60 seconds View demo Usage Install package: pnpm i -D

Nov 2, 2022

A utility for creating toggleable items with JavaScript. Inspired by bootstrap's toggle utility. Implemented in vanillaJS in a functional style.

LUX TOGGLE Demo: https://jesschampion.github.io/lux-toggle/ A utility for creating toggleable dom elements with JavaScript. Inspired by bootstrap's to

Oct 3, 2020

Make the content slide prettily across the screen with variable sizes of scrolling items, in any of four directions, pausing while the mouse is over the marquee, and all with vanilla JavaScript.

TEG Marquee Make the content slide prettily across the screen with variable sizes of scrolling items, in any of four directions, pausing while the mou

Dec 30, 2021

👨🏼‍🎨 It is a virtual blackboard, where you can make 🖌 drawings through 🖱 the mouse. You have the option to choose 🎨 colors and line thickness.

👨🏼‍🎨 It is a virtual blackboard, where you can make 🖌 drawings through 🖱 the mouse. You have the option to choose 🎨 colors and line thickness.

👨🏼‍🎨 Lets Draw 🎨 ÍNDICE 1. Lets-Draw 2. Realization of the Project 3. Technologies used 4. Authors 1. Lets-Draw 👨🏼‍🎨 It is a virtual blackboard

Mar 7, 2022

A powerful javascript library to create amazing and smooth effects for the mouse cursor on your website.

A powerful javascript library to create amazing and smooth effects for the mouse cursor on your website.

Cuberto Mouse Follower A powerful javascript library to create amazing and smooth effects for the mouse cursor on your website. Dependencies GSAP v3 (

Dec 30, 2022

A JavaScript library for adding ripple effects to HTML elements based on mouse events.

About project Ripplejs is an open source javascript library created for the purpose of adding ripple effects to html elements based on mouse events. L

May 10, 2022

A Deno library for interacting with the mouse 🖱️ keyboard ⌨️ and screen 💻

A Deno library for interacting with the mouse 🖱️ keyboard ⌨️ and screen 💻 . Litebot provides a simple API for creating kbm events, macros, & working with displays. Litebot leverages Deno's FFI to allow speedy low level control in C & C++ while having a typescript API exposed to the user.

Aug 30, 2022
Releases(v0.1.3)
Owner
Robert Soriano
[object Object]
Robert Soriano
Super tiny size multi-touch gestures library for the web.    You can touch this →

Preview You can touch this → http://alloyteam.github.io/AlloyFinger/ Install You can install it via npm: npm install alloyfinger Usage var af = new Al

腾讯 AlloyTeam 3.3k Dec 12, 2022
Canvas-based JavaScript UI element implementing touch, keyboard, mouse and scroll wheel support.

pure-knob Initially a (circular) knob / dial control with mouse, wheel, touch and keyboard support, implemented in pure JavaScript. In addition, this

Andre Plötze 44 Nov 4, 2022
Pressure is a JavaScript library for handling both Force Touch and 3D Touch on the web

Pressure is a JavaScript library for handling both Force Touch and 3D Touch on the web, bundled under one library with a simple API that makes working with them painless.

Stuart Yamartino 2.9k Dec 29, 2022
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
It's not butter, but it's root.

margerine Episode 2: Revenge of the ¯\_(ツ)_/¯ margerine is a root exploit and adb enabler for the DJI Air Unit (wm150), Caddx Vista (lt150), FPV Goggl

fpv.wtf 183 Dec 24, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
A Svelte parser that compiles to Mitosis JSON, allowing you to write Svelte components once and compile to every framework.

Sveltosis Still in development A Svelte parser that compiles to Mitosis JSON, allowing you to write Svelte components once and compile to every framew

sveltosis 70 Nov 24, 2022
App that allows you to control and watch YouTube videos using hand gestures. Additionally, app that allows you to search for videos, playlists, and channels.

YouTube Alternative Interaction App An app I made with Edward Wu that allows you to search and watch videos from YouTube. Leverages Google's YouTube D

Aaron Lam 2 Dec 28, 2021
Conveyer adds Drag gestures to your Native Scroll.

Conveyer Demo / Documentation / Other components Conveyer adds Drag gestures to your Native Scroll. ?? ?? ?? ✨ Features You can use Native Scroll-like

NAVER 70 Dec 15, 2022