react-use-gesture

编程之家收集整理的这个编程导航主要介绍了react-use-gesture编程之家,现在分享给大家,也给大家做个参考。

react-use-gesture

react-use-gesture 介绍

react-use-gesture是一个钩子,可以将更丰富的鼠标和触摸事件绑定到任何组件或视图。使用您收到的数据,设置手势变得微不足道,并且通常只需要几行代码。  

简单的例子

示例使div拖拽成为可拖动,以便在拖动时跟随鼠标,并在发布时返回其初始位置。

import { useSpring,animated } from 'react-spring'

import { useDrag } from 'react-use-gesture'

function PullRelease() {

const [{ xy },set] = useSpring(() => ({ xy: [0,0] }))

// 1. Define the gesture

const bind = useDrag(({ down,delta }) => set({ xy: down ? delta : [0,0] }))

return (

<animated.div

// 2. Bind it to a component

{...bind()}

{{ transform: xy.interpolate((x,y) => `translate3D(${x}px,${y}px,0)`) }} />

GitHub:https://github.com/react-spring/react-use-gesture

网站描述:组件绑定鼠标/触摸手势的小助手

react-use-gesture官方网站

官方网站:

如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。

相关文章

WXPage,一个极其轻量的微信小程序开发框架
PhoneGap,一个采用HTML,CSS和JavaScript的技术,创建移动跨...
Mobiscroll,渐进式Web和混合应用程序的跨平台UI控件
Remax,全新的小程序开发体验
mobilebone.js,单页切换骨架
WeZRender,微信小程序Canvas开发