CSS比例尺和可滚动容器中的中心图像而无需裁剪
我想缩放图像,以便用户可以在变焦后滚动。 以下示例效果很好,但我必须将原点设置为左上角,否则图像被裁剪到顶部和左上。无论如何,是否可以扩展到图像的中心(就像我省略转换原素时发生的那样),但没有裁剪?
请注意,我使用比例尺,因为图像将具有关联的图像映射,因此我不能仅设置宽度和高度。
#container {
width: 500px;
height: 500px;
overflow: auto;
}
#pic {
transform: scale(2);
transform-origin: top left;
}
<div id="container">
<img id="pic" src="https://picsum.photos/id/237/500/500" >
</div>
I'd like to zoom an image so that the user can scroll around it after the zoom.
The following example works well but I have to set the origin to top left as otherwise the image is cropped to the top and left. Is there anyway to scale to the centre of the image (as happens when I omit the transform-origin) but without cropping?
Please note I'm using scale because the image will have an associated image map so I can't just set the width and height.
#container {
width: 500px;
height: 500px;
overflow: auto;
}
#pic {
transform: scale(2);
transform-origin: top left;
}
<div id="container">
<img id="pic" src="https://picsum.photos/id/237/500/500" >
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此代码在这里,修复程序是右上角,
位置:绝对;
This code right here, fixes is to top right, with
position:absolute;