react-zoom-pan-pinch icon indicating copy to clipboard operation
react-zoom-pan-pinch copied to clipboard

Auto fit large images on init

Open xairoo opened this issue 4 years ago • 2 comments

How to fit large images to the outer size on init automatically? An example would be really great!

xairoo avatar Oct 25 '21 23:10 xairoo

Hi! Did you ever find the solution?

dtemir avatar Jun 14 '22 16:06 dtemir

This helped me!

https://github.com/prc5/react-zoom-pan-pinch/issues/210#issuecomment-869022544

you can just add styles to the image itself to be 100% width of the component, this way it will be responsive

Minimal example:

import myimg from "./myimg.png";

import { TransformWrapper, TransformComponent } from "react-zoom-pan-pinch";

export const Example = () => {
    return (
        <div style={{ width: "600px", height: "400px" }}>
            <TransformWrapper>
                <TransformComponent>
                    <img src={myimg} alt="" style={{width: "100%"}} />
                </TransformComponent>
            </TransformWrapper>
        </div>
    );
};

zimonitrome avatar May 10 '23 23:05 zimonitrome