//自动调整图像大小,将图片限制在一定范围,保持比例平衡!
//我的想法是,获的原始图象大小,然后按百分比缩小,直到小于规定的大小。j是每次减去的量。可以调按实际调整。
//调用方法:<img id="a1" name="a1" src="图片路径 onload="AdjustImage(500,350,tihs.id)" /> 将图片限制在500,350比例范围内,保持比例。注意,不要写width,与height属性。
//IE6.0 IE7.0 firefox 试过了,好用,多张图片只要保持Id唯一就可
function AdjustImage(w,h,id)
{
var width=w,height=h;
var el=document.getElementById(id);
var imgWidth=el.width,imgHeight=el.height;
var i=100,j=1,newWidth,newHeight;
if(imgWidth>=width||imgHeight>=height)
{
while(i>0)
{
i=i-j;
newWidth=imgWidth*(i/100);
newHeight=imgHeight*(i/100);
if(newWidth<width&&newHeight<height) break;
}
el.width=newWidth;
el.height=newHeight;
}
}
