react-quick-pinch-zoom
Version:
A react component that providing multi-touch gestures for zooming and dragging on any DOM element.
68 lines (47 loc) • 2.23 kB
Markdown
[](https://www.npmjs.com/package/react-quick-pinch-zoom)
[](https://www.npmtrends.com/react-quick-pinch-zoom)
[](https://bundlephobia.com/result?p=react-quick-pinch-zoom)
[](https://github.com/retyui/react-quick-pinch-zoom/actions/workflows/nodejs.yml)
A react component that lets you zooming and dragging on any DOM element using multi-touch gestures on mobile devices
and mouse-events\wheel on desktop devices.
Based on this module [manuelstofer/pinchzoom](https://github.com/manuelstofer/pinchzoom)
- 🔮 Simple. Easy to use;
- 🍎 It works with mobile touch gestures and desktop mouse events;
- ⚡ Fast, 60 FPS on mobile devices.
- [API documentation](docs/api/README.md)
- [Web demos](https://react-quick-pinch-zoom.netlify.com/)
```bash
yarn add react-quick-pinch-zoom
```
[](https://media.giphy.com/media/ggJk8Rmysy6TcKJj5K/giphy.mp4)
[](https://media.giphy.com/media/ggJk8Rmysy6TcKJj5K/giphy.mp4)
```jsx harmony
import React, { useCallback, useRef } from "react";
import QuickPinchZoom, { make3dTransformValue } from "react-quick-pinch-zoom";
const IMG_URL =
"https://user-images.githubusercontent.com/4661784/" +
"56037265-88219f00-5d37-11e9-95ef-9cb24be0190e.png";
export const App = () => {
const imgRef = useRef();
const onUpdate = useCallback(({ x, y, scale }) => {
const { current: img } = imgRef;
if (img) {
const value = make3dTransformValue({ x, y, scale });
img.style.setProperty("transform", value);
}
}, []);
return (
<QuickPinchZoom onUpdate={onUpdate}>
<img ref={imgRef} src={IMG_URL} />
</QuickPinchZoom>
);
};
```
MIT © [retyui](https://github.com/retyui)