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 many options
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";
class Example extends Component {
render() {
return (
<TransformWrapper>
<TransformComponent>
<img src="image.jpg" alt="test" />
</TransformComponent>
</TransformWrapper>
);
}
}
or
import React, { Component } from "react";
import { TransformWrapper, TransformComponent } from "react-zoom-pan-pinch";
class Example extends Component {
render() {
return (
<TransformWrapper
initialScale={1}
initialPositionX={200}
initialPositionY={100}
>
{({ zoomIn, zoomOut, resetTransform, ...rest }) => (
<React.Fragment>
<div className="tools">
<button onClick={zoomIn}>+</button>
<button onClick={zoomOut}>-</button>
<button onClick={resetTransform}>x</button>
</div>
<TransformComponent>
<img src="image.jpg" alt="test" />
<div>Example text</div>
</TransformComponent>
</React.Fragment>
)}
</TransformWrapper>
);
}
}
MIT Β© prc5
Thanks goes to these wonderful people (emoji key):
Maciej Pyrc π π» π π§ π‘ π¬ |
This project follows the all-contributors specification. Contributions of any kind welcome!