pmndrs/use-gesture
pmndrs/use-gesture has 9,626 GitHub stars and 337 forks. GitHot measured -1 stars in 24 hours and -2 in 7 days. Last checked 2026-11-13 01:08 UTC. Last push 2024-07-15.
측정된 스타 증가
- in 24h
- -1
- in 7 days
- -2
- in 15 days
- 업데이트 지연
- in 1 month
- 업데이트 지연
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
소개
👇Bread n butter utility for component-tied mouse/touch gestures in React and Vanilla Javascript.
웹 및 앱README.md
Original@use-gesture
@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...
관련 프로젝트 살펴보기
freeCodeCamp/freeCodeCamp
freeCodeCamp.org의 오픈 소스 코드베이스와 커리큘럼입니다. 수학, 프로그래밍, 컴퓨터 과학을 무료로 배울 수 있습니다.
459,089 스타donnemartin/system-design-primer
대규모 시스템 설계 방법을 배우고 시스템 설계 면접을 준비할 수 있습니다. Anki 플래시카드가 포함되어 있습니다.
377,770 스타react/react
웹과 네이티브 사용자 인터페이스를 위한 라이브러리.
252,577 스타vuejs/vue
Vue 2 저장소입니다. Vue 3은 https://github.com/vuejs/core를 방문하세요.
212,527 스타





