All Projects → pmndrs → use-gesture

pmndrs / use-gesture

Licence: MIT license
👇Bread n butter utility for component-tied mouse/touch gestures in React and Vanilla Javascript.

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to use-gesture

React Use Gesture
👇Bread n butter utility for component-tied mouse/touch gestures in React and Vanilla Javascript.
Stars: ✭ 5,704 (-13.89%)
Mutual labels:  hooks, wheel, drag, scroll, zoom, gestures, pinch
React Indiana Drag Scroll
React component which implements scrolling via holding the mouse button or touch
Stars: ✭ 190 (-97.13%)
Mutual labels:  drag, scroll
React Native Easy Gestures
React Native Gestures. Support: Drag, Scale and Rotate a Component.
Stars: ✭ 153 (-97.69%)
Mutual labels:  drag, gestures
Use Scroll Position
Use scroll position ReactJS hook done right
Stars: ✭ 414 (-93.75%)
Mutual labels:  hooks, scroll
React Prismazoom
A pan and zoom component for React, using CSS transformations.
Stars: ✭ 29 (-99.56%)
Mutual labels:  drag, zoom
Dragscroll
micro library for drag-n-drop scrolling style
Stars: ✭ 989 (-85.07%)
Mutual labels:  drag, scroll
use-scroll-direction
A simple, performant, and cross-browser hook for detecting scroll direction in your next react app.
Stars: ✭ 24 (-99.64%)
Mutual labels:  hooks, scroll
Pd Select
vue components ,like ios 3D picker style,vue 3d 选择器组件,3D滚轮
Stars: ✭ 101 (-98.48%)
Mutual labels:  wheel, scroll
React Native Swiper Flatlist
👆 Swiper component implemented with FlatList using Hooks & Typescript + strict automation tests with Detox
Stars: ✭ 217 (-96.72%)
Mutual labels:  hooks, scroll
anim-event
Event Manager for Animation
Stars: ✭ 25 (-99.62%)
Mutual labels:  drag, scroll
embla-carousel-wheel-gestures
wheel interactions for Embla Carousel
Stars: ✭ 30 (-99.55%)
Mutual labels:  wheel, gestures
Scrollbooster
Enjoyable content drag-to-scroll library
Stars: ✭ 775 (-88.3%)
Mutual labels:  drag, scroll
Wxp Ui
小程序插件合集(下拉刷新, 拖拽排序, 索引列表, 日期选择, 侧滑删除...)
Stars: ✭ 636 (-90.4%)
Mutual labels:  drag, scroll
Snap.svg.zpd
A zoom/pan/drag/rotate plugin for Snap.svg (useful for view only)
Stars: ✭ 119 (-98.2%)
Mutual labels:  drag, zoom
lovelace-plotly-graph-card
Highly customisable Lovelace card to display interactive graphs. Brings scrolling, zooming, and much more!
Stars: ✭ 38 (-99.43%)
Mutual labels:  scroll, zoom
use-smooth-scroll
React hook which gives a smooth scrolling function.
Stars: ✭ 41 (-99.38%)
Mutual labels:  hooks, scroll
gesto
You can set up drag, pinch events in any browser.
Stars: ✭ 47 (-99.29%)
Mutual labels:  drag, pinch
core
Renderer for tldraw and maybe you, too.
Stars: ✭ 418 (-93.69%)
Mutual labels:  zoom, pinch
react-hooks-library
A collection of hooks and utilities for modern React
Stars: ✭ 236 (-96.44%)
Mutual labels:  hooks
SSCycleScrollView
轮播终结者,用swift完成,易用集成
Stars: ✭ 39 (-99.41%)
Mutual labels:  scroll

@use-gesture

npm (tag) npm bundle size NPM Discord Shield

@use-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.

You can use it stand-alone, but to make the most of it you should combine it with an animation library like react-spring, though you can most certainly use any other.

The demos are real click them!

Installation

React

#Yarn
yarn add @use-gesture/react

#NPM
npm install @use-gesture/react

Vanilla javascript

#Yarn
yarn add @use-gesture/vanilla

#NPM
npm install @use-gesture/vanilla

Full documentation website

Simple example

React
import { useSpring, animated } from '@react-spring/web'
import { useDrag } from '@use-gesture/react'

function Example() {
  const [{ x, y }, api] = useSpring(() => ({ x: 0, y: 0 }))

  // Set the drag hook and define component movement based on gesture data.
  const bind = useDrag(({ down, movement: [mx, my] }) => {
    api.start({ x: down ? mx : 0, y: down ? my : 0 })
  })

  // Bind it to a component.
  return <animated.div {...bind()} style={{ x, y, touchAction: 'none' }} />
}
Vanilla javascript
<!-- index.html -->
<div id="drag" />
// script.js
const el = document.getElementById('drag')
const gesture = new DragGesture(el, ({ active, movement: [mx, my] }) => {
  setActive(active)
  anime({
    targets: el,
    translateX: active ? mx : 0,
    translateY: active ? my : 0,
    duration: active ? 0 : 1000
  })
})

// when you want to remove the listener
gesture.destroy()

The example above makes a div draggable so that it follows your mouse on drag, and returns to its initial position on release.

Make sure you always set touchAction on a draggable element to prevent glitches with the browser native scrolling on touch devices.

Available hooks

@use-gesture/react exports several hooks that can handle different gestures:

Hook Description
useDrag Handles the drag gesture
useMove Handles mouse move events
useHover Handles mouse enter and mouse leave events
useScroll Handles scroll events
useWheel Handles wheel events
usePinch Handles the pinch gesture
useGesture Handles multiple gestures in one hook

More on the full documentation website...

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].