//图片加载并按比例缩小到合适大小
//
<img src=””  width=”80″ onload=”DownImage(this,80,0,0);”>
function DownImageWidth(ImgD,MaxWidth,alignX,alignY)
{
    alignX
=alignX||1;
    alignY
=alignY||1;
   
var image=new Image();
    image.src
=ImgD.src;
   
if(image.width>0 && image.height>0)
    {
       
var rate = MaxWidth/image.width;
        var wid=0;
       
var hid=0;
       
if(rate <= 1)
        {
            wid
=ImgD.width=image.width*rate;
            hid
=ImgD.height=image.height*rate;
        }
       
else
        {
            wid
=ImgD.width=image.width;
            hid
=ImgD.height=image.height;
        }
    }
}

版权声明:本文为MineDream原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/MineDream/archive/2011/04/22/2024875.html