这段限制图片大小的代码该怎么用呢?
#cont img { max-width: 400px;max-height: 400px;width:expression(onload=function(){if (this.offsetWidth>this.offsetHeight){this.style.width=(this.offsetWidth > 400)?"400px":"auto"}{this.style.height=(this.offsetHeight < 400)?"auto":"400px"}});border:0px;}我的论坛的图片显示BBcode是
'#IMAGE
if isFound(str,"") > 0 AND isFound(str,"javascript:") = 0 then
imageIndex = imageIndex + 1
str= Replace(str,"[img=","<br><img onclick=""userImage" & imageIndex & """ onload=""javascript:if(this.width> screen.width/2) this.width=screen.width/2"" id='userImage" & imageIndex & "' src=")
str = Replace(str,"]",">")
isChange = false
End if
该怎么组合呢? 这段代码是css里的,看错了,有用,直接插css里就可以
不过,你把这段加在html的head上面也可以
<script type="text/javascript">
window.onload=function(){
var imgsrc=document.images;
for(i=0;i<imgsrc.length;i++) {
if(imgsrc.width>500) {
imgsrc.width=499;
}
}
}
</script>
[ 本帖最后由 我踏MJ而来 于 2007-1-2 18:55 编辑 ] 直接放到css里就可以了吗 对,但是相对图片的大区域要加个cont的id 我的论坛顶端有一个超宽的图片,所以用了你的代码,那个图片就会变小,但是其他图片不变:)
<script type="text/javascript">
window.onload=function(){
var imgsrc=document.images;
for(i=0;i<imgsrc.length;i++) {
if(imgsrc.width>500 && imgsrc.ref!='keep') {
imgsrc.width=499;
}
}
}
</script>
不想变的图片加一个ref="keep"的属性,具体的限制大小改500和499 :lol :lol 。。。。。。。。。。。 :) :) 真是太谢谢你啦,我苦恼已久的问题终于解决了,呵呵呵。 小白素强人
膜拜ing
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>css</title>
<style type="text/css">
body {}
img {border:0;}
.article {width:200px; height:100px; background:#ccc;}
.article img {
max-width: 200px;
max-height: 200px;
width:
expression(onload=function(){if (this.offsetWidth>this.offsetHeight)
{this.style.width=(this.offsetWidth > 200)?"200px":"auto"}
{this.style.height=(this.offsetHeight < 200)?"auto":"200px"}
});
}
</style>
</head>
<body>
<div class="article">
<img src="http://jgwy.net/bbs/images/server.gif" />
<br />
<img src="http://www.jgwy.net/bbs/images/smilies/smile.gif" />
<br />
容器width=200px
</div>
</body>
</html>
但注意,expression是相当耗cpu的,不能用太多
页:
[1]
2