[导入]用脚本控制签名图大小
最近论坛有人使用超长签名图 找了一下CS的解决方案 是通过脚本判断页面里的每个图片大小实现的 没有错误的代码如下:
<script language="javascript">
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 = 550;
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);
}
}script>
如:
原图效果:http://poy.cn/down/maxsize.gif
缩小后的效果http://poy.cn/forums/PostAttachment.aspx?PostID=21940
文章来源:http://127.0.0.1/blog/hyouhaku/archive/2005/08/02/306.html