我有 3 个 div,变换位于第二个 div 上,其中有一个 div。我添加了放大和缩小按钮,但是当我放大时,我无法一直滚动到左侧和顶部,但滚动到右侧和底部时没有问题。我还想要一些填充,以便放大时父 div 会显示一点。我正在尝试复制 pdf 查看器。
import React, { useState } from "react";
function Home() {
const [scale, setScale] = useState(1);
const handleZoomIn = () => {
setScale((prevScale) => prevScale + 0.1);
};
const handleZoomOut = () => {
setScale((prevScale) => prevScale - 0.1);
};
return (
<div
style={{
width: "100vw",
height: "calc(100vh - 80px)",
display: "flex",
justifyContent: "center",
alignItems: "center",
padding: "10px"
}}
>
<button onClick={handleZoomIn}>Zoom In</button>
<button onClick={handleZoomOut}>Zoom Out</button>
<div
style={{
width: "40%",
height: "100%",
background: "yellow",
display: "flex",
justifyContent: "center",
alignItems: "center",
overflow:"scroll",
}}
>
<div
style={{
width: "80%",
background: "red",
height: "80%",
display: "flex",
justifyContent: "center",
alignItems: "center",
transform: `scale(${scale})`,
}}
>
<div
style={{ width: "95%", background: "blue", height: "95%" }}
></div>
</div>
</div>
</div>
);
}
export default Home;
只是不确定如何解决这个问题