图片按比例缩放JS代码

                    <script language="javascript" type="text/javascript">
function changimgsize(){
var imgs = document.getElementById("content").getElementsByTagName("img");
var imgwidth=100;
for(i=0; i <imgs.length; i++){
if(imgs[i].width>imgwidth){
var oW = imgs[i].width;
var oH = imgs[i].height;
var rate = oH/oW;
imgs[i].width = imgwidth;
imgs[i].height = imgwidth*rate;
}
}
}
window.onload=changimgsize;
</script>

你可能感兴趣的:(js)