用JS控制页面图的图片大小的通用代码

| |
[晴 October 12, 2006 08:42 | by jed ]
这个一般用于文章查看的页面,针对新闻性质的网站,此外这个算法是直接分析网页中所有图片的,因此如果你的版面设计中有比指定宽度大的图片是不能用这个函数的(或者用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>



Tags:
代码编程 | 评论(0) | 引用(0) | 阅读(1045)
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
昵称   密码   游客无需密码
网址   电邮   [注册]