我需要将当前窗口大小缩小到客户机窗口85%大小的图像太大。为此,我创建了一个适用于onload和onresize事件的函数。但是,出事了:(在调整页面大小时调整图像的大小页面
function a(){
var img = document.getElementsByTagName("img")
var goodWidth = document.body.clientWidth*0.85
for(i=0;i<img.length;i++){
img[i].maxWidth=img[i].width
if(img[i].width>goodWidth){
img[i].width=goodWidth
}
if((img[i].width<img[i].maxWidth) and (img[i].width<goodWidth)){
img[i].width=goodWidth
}
}
}
我对我的纯描述抱歉现在我会尝试修复它。 例如,我有这个尺寸的图像: 1.1920x1080,2.1280x720,3 。640x480的所有图像的大小应在浏览器窗口的大小不超过85%,那应该怎么工作:
For resolution 1680x1050:
Picture 1: (1680 * 0,85) x (1050 * 0.85);
Picture 2: 1280x720;
Picture 3: 640x480;
For resolution 800x600:
Picture 1: (1680 * 0,85) x (1050 * 0.85);
Picture 2: (1280 * 0.85) x (720 * 0.85);
Picture 3: 640x480;
When the resolution of the browser window again increase to 1680x1050:
Picture 1: (1680 * 0,85) x (1050 * 0.85);
Picture 2: 1280x720;
Picture 3: 640x480;
请描述,尽你所能,哪里出了问题:什么期望/预期会发生什么确实发生了。 – Faust
为什么不依靠** CSS ** **响应式设计** _image resizing_:img {max-width:100%;},它会根据窗口和容器大小调整图像大小? – datelligence