5

除了重置缩放以强制图像在使用Panzoom 库进行平移时不会完全丢失之外,还有其他方法吗

const element = document.querySelector('#scene');

const zoomLevels = [0.1, 0.25, 0.5, 0.75, 1, 1.25, 1.5, 1.75, 2, 2.5, 3];
let currentZoomLevel = zoomLevels[4];
const text = document.querySelector('#text');

let panZoomController = panzoom(element);
div {
  overflow: hidden;
  border: 3px solid red
}

img {
  cursor: move;
}
<script src="https://unpkg.com/panzoom@8.1.0/dist/panzoom.min.js"></script>

<body>
  <div>
    <img id="scene" src="https://www.probytes.net/wp-content/uploads/2018/01/5-1.png">
  </div>

  <br/>
<span>Image should not be Dragged /panned out of the view</span>
</body>

4

2 回答 2

0

似乎有 bounds 属性

const element = document.querySelector('#scene');

const zoomLevels = [0.1, 0.25, 0.5, 0.75, 1, 1.25, 1.5, 1.75, 2, 2.5, 3];
let currentZoomLevel = zoomLevels[4];
const text = document.querySelector('#text');

let panZoomController = panzoom(element, {
  bounds: true,
  boundsPadding: 0.1
});
div {
  overflow: hidden;
  border: 3px solid red
}

img {
  cursor: move;
}
<script src="https://unpkg.com/panzoom@8.1.0/dist/panzoom.min.js"></script>

<body>
  <div>
    <img id="scene" src="https://www.probytes.net/wp-content/uploads/2018/01/5-1.png">
  </div>

  <br/>
  <span>Image should not be Dragged /panned out of the view</span>
</body>

于 2019-07-20T22:07:04.407 回答
0
let panZoomController = panzoom(element, {
  bounds: true,
  boundsPadding: 1
});
于 2021-12-30T14:30:22.083 回答