标签:bsp img ges elements 大小 idt 定义 图片显示 document
//缩放图片到合适大小
function ResizeImages() {
var myimg, oldwidth, oldheight;
var maxwidth = 400;
var maxheight = 400
var imgs = document.getElementById(‘article‘).getElementsByTagName(‘img‘); //如果你定义的id不是article,请修改此处
for (i = 0; i < imgs.length; i++) {
myimg = imgs[i];
if (myimg.width > myimg.height) {
if (myimg.width > maxwidth) {
oldwidth = myimg.width;
myimg.height = myimg.height * (maxwidth / oldwidth);
myimg.width = maxwidth;
}
} else {
if (myimg.height > maxheight) {
oldheight = myimg.height;
myimg.width = myimg.width * (maxheight / oldheight);
myimg.height = maxheight;
}
}
}
}
//缩放图片到合适大小
ResizeImages();
</script>
标签:bsp img ges elements 大小 idt 定义 图片显示 document
原文地址:https://www.cnblogs.com/4job/p/9962686.html