All Projects β†’ wouterraateland β†’ use-pan-and-zoom

wouterraateland / use-pan-and-zoom

Licence: MIT license
πŸ‘†+πŸ”Ž React hook for panning and zooming a container

Programming Languages

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

Projects that are alternatives of or similar to use-pan-and-zoom

Advance
Physics-based animations for iOS, tvOS, and macOS.
Stars: ✭ 4,445 (+7698.25%)
Mutual labels:  interaction, gestures
socitrack
A wearable platform for social interaction studies
Stars: ✭ 16 (-71.93%)
Mutual labels:  interaction
hodux
πŸš€Simple reactive React Hooks state management.
Stars: ✭ 29 (-49.12%)
Mutual labels:  react-hooks
notebookJS
notebookJS: seamless JavaScript integration in Python Notebooks
Stars: ✭ 149 (+161.4%)
Mutual labels:  interaction
promotion-web
基于React: v18.x.x/Webpack: v5.x.x/React Router v6.x.x/ Antd: v5..x.x/Fetch Api/ Typescript: v4.x.x η­‰ζœ€ζ–°η‰ˆζœ¬θΏ›θ‘Œζž„ε»Ί...
Stars: ✭ 374 (+556.14%)
Mutual labels:  react-hooks
next-qrcode
React hooks for generating QRCode for your next React apps.
Stars: ✭ 87 (+52.63%)
Mutual labels:  react-hooks
flutter use
Play Flutter Hooks.
Stars: ✭ 150 (+163.16%)
Mutual labels:  react-hooks
use-async-resource
A custom React hook for simple data fetching with React Suspense
Stars: ✭ 92 (+61.4%)
Mutual labels:  react-hooks
MonsterJS
MonsterJS - a game for learning JavaScript DOM Selectors while playing!
Stars: ✭ 26 (-54.39%)
Mutual labels:  react-hooks
react-stateful
A simple implementation of React-State-Hook and React-Effect-Hook to show how React-Hooks work
Stars: ✭ 34 (-40.35%)
Mutual labels:  react-hooks
web
React hooks done right, for browser and SSR.
Stars: ✭ 940 (+1549.12%)
Mutual labels:  react-hooks
ReactZooApp
ReactZooApp
Stars: ✭ 33 (-42.11%)
Mutual labels:  interaction
device-orientation
React hook for the Device Orientation API
Stars: ✭ 23 (-59.65%)
Mutual labels:  react-hooks
awesome-web-react
πŸš€ Awesome Web Based React πŸš€ Develop online with React!
Stars: ✭ 31 (-45.61%)
Mutual labels:  react-hooks
Blog-React-Hook-Tutorial
This is a beginner tutorial for react hooks I have written in dev.to and Medium
Stars: ✭ 21 (-63.16%)
Mutual labels:  react-hooks
covid-19-stats
Get the latest COVID-19 statistics by country
Stars: ✭ 41 (-28.07%)
Mutual labels:  react-hooks
Forum-App-React-Frontend
This is the React client that consumes the API built here: https://github.com/victorsteven/Forum-App-Go-Backend
Stars: ✭ 39 (-31.58%)
Mutual labels:  react-hooks
react-use-hubspot-form
Embed HubSpot forms into your React components using hooks! Works with Create React App, Gatsby and other platforms.
Stars: ✭ 41 (-28.07%)
Mutual labels:  react-hooks
processor
A simple and lightweight JavaScript data processing tool. Live demo:
Stars: ✭ 27 (-52.63%)
Mutual labels:  react-hooks
react-sage
Handy-dandy React hooks.
Stars: ✭ 21 (-63.16%)
Mutual labels:  react-hooks

use-pan-and-zoom

πŸ‘†+πŸ”Ž React hook for panning and zooming a container.

Supports touch devices since version 0.4.0.

Installation

yarn add use-pan-and-zoom / npm install use-pan-and-zoom --save

Requirements

This package is a React Hook and therefor requires React 16.8 or newer.

Quick Start

import usePanZoom from "use-pan-and-zoom";

export default function Demo() {
  const { transform, setContainer, panZoomHandlers } = usePanZoom();

  return (
    <div
      ref={(el) => setContainer(el)}
      style={{ touchAction: "none" }}
      {...panZoomHandlers}
    >
      <div style={{ transform }}>
        <p>Drag to πŸ‘† and scroll / pinch to πŸ”Ž me!</p>
      </div>
    </div>
  );
}

Edit use-pan-and-zoom example

Parameters

All parameters are optional

Parameter Type Default
enablePan boolean true
enableZoom boolean true
requireCtrlToZoom boolean false
disableWheel boolean false
panOnDrag boolean true
preventClickOnPan boolean true
zoomSensitivity number 0.01
minZoom number 0
maxZoom number Infinity
minX number -Infinity
maxX number Infinity
minY number -Infinity
maxY number Infinity
initialZoom number 1
initialPan position { x: 0, y: 0 }
onPanStart (touches: position[], transform: transform) => void () => {}
onPan (touches: position[], transform: transform) => void () => {}
onPanEnd () => void () => {}
onZoom (transform: transform) => void () => {}

Where:

  • position = { x: number, y: number }
  • transform = { x: number, y: number, zoom: number }

Output

Field Type Description
container HTMLElement | null Current container element
setContainer (HTMLElement | null) => void Sets the container element
transform string CSS string determining the transform
center position Center of container element
pan position Current pixels panned
zoom number Current zoom
setPan (pan: position) => void Set pan imperatively
setZoom (zoom: number) => void Set zoom imperatively
panZoomHandlers { ...EventHandler } Pass to container element to listen to relevant events
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].