百度空间 | 百度首页 
 
查看文章
 
关于网站图片的自动限制尺寸问题
2009-05-30 09:38
传统的方法:这种方法只能是修改编辑器里面增加js
<img onload="javascript:if(this.width>560)this.width=560;" src="upfile_pic/url.jpg">
<img alt="" src="uploadfile/url.jpg" onload="javascript:if(this.width>screen.width-333)this.width=screen.width-333" >
现在的方法:使用js和css结合
<script>
function SetImg(obj){
if(obj.offsetWidth>obj.offsetHeight)
obj.style.width=obj.offsetWidth>=200?"200px":"auto"
else
obj.style.height=obj.offsetHeight>=200?"200px":"auto"
}
</script>
<style>
img{max-width:200px;max-height:200px;star : expression(typeof(SetImg)=="function"?SetImg(this):"");}
</style>
</head>
<body>
<div><img src="url.jpg" /></div>
</body>
效果还是非常好的。

类别:Web | 添加到搜藏 | 浏览() | 评论 (0)
 
最近读者:
 
网友评论:
发表评论:
姓 名:
网址或邮箱: (选填)
内 容:
验证码: 请点击后输入四位验证码,字母不区分大小写
      

     

©2009 Baidu