JSFiddle - React, Tailwind, and code Playground
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width" />
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@fancyapps/[email protected]/dist/panzoom/panzoom.css"
/>
<style>
#myPanzoom {
max-width: 600px;
height: 300px;
background: #eee;
}
</style>
</head>
<body>
<div>
<div class="f-panzoom" id="myPanzoom">
<img class="f-panzoom__content" src="https://lipsum.app/id/1/1200x1500" />
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/@fancyapps/[email protected]/dist/panzoom/panzoom.umd.js"></script>
<script>
const container = document.getElementById("myPanzoom");
const instance = new Panzoom(container, {
panMode: 'mousemove',
mouseMoveFactor: 1.25,
click: false,
wheel: false
});
container.addEventListener("mouseenter", (event) => {
if (!event.buttons) {
instance.zoomToCover(event);
}
});
container.addEventListener("mouseleave", () => {
instance.zoomToFit();
});
</script>
</body>
</html>