Super fast and light react npm package for zooming, panning and pinching html elements in easy way
- ๐ Fast and easy to use
- ๐ญ Light, without external dependencies
- ๐ Mobile gestures, touchpad gestures and desktop mouse events support
- ๐ Powerful context usage, which gives you a lot of freedom
- ๐ง Highly customizable
- ๐ Animations and Utils to create own tools
- ๐ฎ Advanced hooks and components
Do you like this library? Try out other projects
โกHyper Fetch - Fetching and realtime data exchange framework.
npm install --save react-zoom-pan-pinch
or
yarn add react-zoom-pan-pinch
import React, { Component } from "react";
import { TransformWrapper, TransformComponent } from "react-zoom-pan-pinch";
const Example = () => {
return (
<TransformWrapper>
<TransformComponent>
<img src="image.jpg" alt="test" />
</TransformComponent>
</TransformWrapper>
);
};
or
import React, { Component } from "react";
import {
TransformWrapper,
TransformComponent,
useControls,
} from "react-zoom-pan-pinch";
const Controls = () => {
const { zoomIn, zoomOut, resetTransform } = useControls();
return (
<div className="tools">
<button onClick={() => zoomIn()}>+</button>
<button onClick={() => zoomOut()}>-</button>
<button onClick={() => resetTransform()}>x</button>
</div>
);
};
const Example = () => {
return (
<TransformWrapper
initialScale={1}
initialPositionX={200}
initialPositionY={100}
>
{({ zoomIn, zoomOut, resetTransform, ...rest }) => (
<>
<Controls />
<TransformComponent>
<img src="image.jpg" alt="test" />
<div>Example text</div>
</TransformComponent>
</>
)}
</TransformWrapper>
);
};
MIT ยฉ prc5