prevent error occurering due to zoom in -out
This commit is contained in:
parent
d7caf47498
commit
4238157fd4
@ -1,4 +1,4 @@
|
||||
import { useState, useRef } from "react";
|
||||
import { useState, useRef ,useEffect} from "react";
|
||||
|
||||
const PreviewDocument = ({ imageUrl }) => {
|
||||
const [loading, setLoading] = useState(true);
|
||||
@ -20,6 +20,16 @@ const PreviewDocument = ({ imageUrl }) => {
|
||||
setZoom((prev) => Math.min(Math.max(prev + delta, 0.5), 3));
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const container = containerRef.current;
|
||||
if (!container) return;
|
||||
|
||||
container.addEventListener("wheel", handleWheel, { passive: false });
|
||||
|
||||
return () => {
|
||||
container.removeEventListener("wheel", handleWheel);
|
||||
};
|
||||
}, []);
|
||||
const handleMouseDown = (e) => {
|
||||
if (zoom <= 1) return;
|
||||
setIsDragging(true);
|
||||
@ -73,12 +83,11 @@ const PreviewDocument = ({ imageUrl }) => {
|
||||
|
||||
<div
|
||||
ref={containerRef}
|
||||
onWheel={handleWheel}
|
||||
onMouseDown={handleMouseDown}
|
||||
onMouseMove={handleMouseMove}
|
||||
onMouseUp={handleMouseUp}
|
||||
onMouseLeave={handleMouseLeave}
|
||||
className="d-flex justify-content-center align-items-center overflow-hidden border rounded"
|
||||
className="d-flex justify-content-center align-items-center overflow-hidden border rounded "
|
||||
style={{
|
||||
width: "100%",
|
||||
height: "80vh",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user