sách gpt4 ai đã đi

javascript - 相对于 div 中心的图像放大和缩小不起作用

In lại 作者:行者123 更新时间:2023-11-28 11:06:11 28 4
mua khóa gpt4 Nike

我的一个网站中有一个图像缩放属性。我想相对于 div 的中心缩放图像。





缩放功能如下。

function zoom(zm) 
{
img=document.getElementById("pic")
wid=img.width
ht=img.height
img.style.width=(wid*zm)+"px"
img.style.height=(ht*zm)+"px"
}

我想相对于中心缩放图像。提前致谢。

1 Câu trả lời

这个怎么样http://jsfiddle.net/sajith/J6Y3X/

JS

function zoom(zm) {
img = document.getElementById("pic")
wid = img.width
ht = img.height
img.style.width = (wid * zm) + "px"
img.style.height = (ht * zm) + "px"
img.style.marginLeft = "-" + (wid * zm)/2 + "px"
img.style.marginTop = "-" + (ht * zm)/2 + "px"
}

CSS

.img {
width:450px;
height:450px;
}
#pic {
vị trí: tuyệt đối;
left: 225px;
top: 225px;
margin: -225px 0 0 -225px;
}

HTML





关于javascript - 相对于 div 中心的图像放大和缩小不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22243021/

28 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com