两款js图片等比例缩放(兼容IE6,IE7,FF)
代码如下 | 复制代码 |
<script language="网页特效" type="text/javascript"> <!-- function imgauto(i){//你必须给图片提前设定初始宽度和高度,建议直接就是最大宽度和高度 var maxw=250; //定义图片显示的最大宽度 var maxh=250; //定义图片显示的最大高度 var o=new image();o.src=i.src;var w=o.width;var h=o.height;var t;if (w>maxw){t=maxw;}else{t=w;} if ((h*t/w)>maxh){i.height=maxh;i.width=maxh/h*w;}else{i.width=t;i.height=t/w*h;} } --> </script> <img src="/attachments/forumid_42/xp_iustd0jh5ssb.jpg" width="250" height="250" onload="imgauto(this)"> |
代码二
代码如下 | 复制代码 |
<script language="javascript" type="text/javascript"> <!-- function imgauto(i,maxw,maxh){var o=new image();o.src=i.src;var w=o.width;var h=o.height;var t;if (w>maxw){t=maxw;}else{t=w;}if ((h*t/w)>maxh){i.height=maxh;i.width=maxh/h*w;}else{i.width=t;i.height=t/w*h;}} --> </script> <img src="/www.111cn.net/xp_iustd0jh5ssb.jpg" width="250" height="250" onload="imgauto(this,250,250)"> <img src="/xp_iustd0jh5ssb.jpg" width="250" height="250" onload="imgauto(this,250,250)"> |
您可能感兴趣的文章:
两款js图片等比例缩放(兼容IE6,IE7,FF)
css图片按比例缩放实现程序
CSS控制图片等比例缩放
jQuery实现等比例缩放大图片让大图片自适应页面布局
css 图片垂直居中(兼容各主流浏览器,含IE6/IE7)
css里的!important意思?
Jquery在IE7下无法使用 $.ajax解决方法
jquery实现图片等比例缩放以及max-width在ie中不兼容解决
四款css 图片按比例缩放实例(兼容ie6,7,firefox)
基于jquery的防止大图片撑破页面的实现代码(立即缩放)