查看文章 |
关于网站图片的自动限制尺寸问题
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> 效果还是非常好的。 |
最近读者: