我想将图像的初始位置设置为居中,我该怎么做?我不想做 CSS 居中,因为它只会在我第一次希望将位置设置为容器的中心时应用。
我需要保持风格#scene {display: inline-block;}
,否则在边界内平移会中断。
最初如何在加载时将此图像居中
const element = document.querySelector('#scene');
let panZoomController = panzoom(element, {
bounds: true,
boundsPadding: 0.1
});
.image-outer-wrapper {
border: 3px solid red;
overflow: hidden;
height: 500px;
}
img {
cursor: move;
display: flex;
justify-content: center;
}
#scene {
display: inline-block;
}
<script src="https://unpkg.com/panzoom@8.1.0/dist/panzoom.js"></script>
<div class="image-outer-wrapper">
<div id="scene">
<img src="https://www.probytes.net/wp-content/uploads/2018/01/5-1.png">
</div>
</div>