这个一般用于文章查看的页面,针对新闻性质的网站,此外这个算法是直接分析网页中所有图片的,因此如果你的版面设计中有比指定宽度大的图片是不能用这个函数的(或者用id区分开)
<script language="javascript">
function ResizeImages()
{
var myimg,oldwidth;
var maxwidth=600;
for(i=0;i<document.images.length;i++){
myimg = document.images[i];
if(myimg.width > maxwidth)
{
oldwidth = myimg.width;
myimg.width = maxwidth;
myimg.height = myimg.height * (maxwidth/oldwidth);
}
}
}
ResizeImages();
</script>
<script language="javascript">
function ResizeImages()
{
var myimg,oldwidth;
var maxwidth=600;
for(i=0;i<document.images.length;i++){
myimg = document.images[i];
if(myimg.width > maxwidth)
{
oldwidth = myimg.width;
myimg.width = maxwidth;
myimg.height = myimg.height * (maxwidth/oldwidth);
}
}
}
ResizeImages();
</script>
本文介绍了一个JavaScript函数,该函数能够自动调整网页上显示的图片尺寸,确保所有图片的最大宽度不超过设定值,适用于新闻类网站等内容管理系统。

被折叠的 条评论
为什么被折叠?



