JS自动缩小图片 不指定

admin , 2006/05/30 01:52 , 代码片段,演示也有 , Comments(1) , Reads(4787) , Via Original
应sin同学要求,写了个js。好久好久好久没有写了哦~~~都快忘光了。

主要的功能是自动缩小过大的图片,以避免div构造的页面被撑坏。

本来想网上应该有现成的代码可以用,搜了半天发现,都不符合web standards标准。于是我的洁癖心理再次发作,决定自己来写个。

现在firefox、ie、opera下通过测试,但是不知道有没有bug。

代码如下:

// 目的:    自动缩小过大的图片,避免撑坏页面
//*********************************************************
function resizeImg() {
//window.alert("55");
var imageAll=document.getElementById("content").getElementsByTagName("img");
if (imageAll !=null) {
for (i=0; i  if (imageAll[i].width>500) {
  imageAll[i].style.width="100%";
  imageAll[i].onclick=function(){window.open(this.src)};
  imageAll[i].style.cursor="hand";
 }
}
}
}

if (window.addEventListener)
window.addEventListener("load", resizeImg, false);
else if (window.attachEvent)
window.attachEvent("onload", resizeImg);
else
window.onload=resizeImg
rena Homepage
2007/08/12 02:22
不错哦,感谢
Pages: 1/1 First page 1 Final page
Add a comment

Nickname

Site URI

Email

Enable HTML Enable UBB Enable Emots Hidden Remember [Login] [Register]