人的头脑太复杂,时间过得久,有时候连自己也被自己骗了,记下来才是最真实的..
2007年1月10日 11:25
我们经常会遇到在页面中的图片按照我们自己的大小来显示,这样可以让页面看起来更规范一些。
比如我们要在页面种显示130×160的图片,相当于我们将图片放入这样的一个相框那,超过的就缩放到这个框的大小,小的就原样显示。
   我们这里有2种解决办法,
   1,不按照比例的缩放

<script language="javascript">
function changeImg(mypic){
   var xw=130;
   var xl=160;

   var width = mypic.width;
   var height = mypic.height;
                   
   if (width > xw ) mypic.width = xw;
   if (height > xl ) mypic.height = xl;
}
</script>
<img src="sh180.jpg" onload="changeImg(this)">  
 2,按照比例的缩放

<script language="javascript">
function changeImg(mypic){
   var xw=160;
   var xl=180;
       
   var width = mypic.width;
   var height = mypic.height;
   var bili = width/height;        
       
   var A=xw/width;
   var B=xl/height;
       
   if(!(A>1&&B>1))
   {
       if(A<B)
       {
           mypic.width=xw;
           mypic.height=xw/bili;
       }
       if(A>B)
       {
           mypic.width=xl*bili;
           mypic.height=xl;
       }
   }
}
</script>
<img src="sh180.jpg" onload="changeImg(this)">
我要 [保存此页] [收藏此页] [复制此链接QQ/Msn发送]
收藏到 [天天] [和讯] [我摘] [天极] [新浪] [博采] [Del.icio.us]
我们推荐您 快去试试吧!
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]