function ResizeImage(imageid,limitWidth,limitHeight) 
{
var image = new Image();
image.src = imageid.src;

if(image.width <= 0 && image.height <= 0) return;

if(image.width/image.height >= limitWidth/limitHeight)
{
if(image.width > limitWidth)
{
imageid.width = limitWidth;
imageid.height = (image.height*limitWidth)/image.width;
}
}
else if(image.height > limitHeight)
{
imageid.height = limitHeight;
imageid.width = (image.width*limitHeight)/image.height;
}

if (imageid.parentElement.tagName != "A")
{
imageid.onclick = function(){window.open(this.src);}
imageid.style.cursor = "hand";
}
}

window.onload = InitImages;

function InitImages()
{
var maxWidth = 600;
var maxHeight = 800;

var imgs = document.getElementsByTagName("img");

for(var i=0; i < imgs.length; i++)
{
var img = imgs[i];

if(img.width>maxWidth||img.height>maxHeight)
ResizeImage(img, maxWidth, maxHeight);
}
}

以上代码加到Utility里面的global.js中即可。

   var maxWidth = 600;

    var maxHeight = 800;
这里可以设置参数
http://blog.csdn.net/cngkqy/archive/2006/11/28/1418107.aspx

posted on 2007-03-27 15:33  mbskys  阅读(151)  评论(0)    收藏  举报