兼容 IE,Firefox 的图片自动缩放 CSS

时间:2011-09-27 13:36:58 

方法一

  1. .Image {  

  2.     max-width:600px;height:auto;cursor:pointer;  

  3.     border:1px dashed #4E6973;padding: 3px;  

  4.     zoom:expr

    ession( function(elm) {  

  5.         if (elm.width>560) {  

  6.             var oldVW = elm.width; elm.width=560;  

  7.             elm.height = elm.height*(560 /oldVW); 

  8.         } 

  9.         elm.style.zoom = '1'; 

  10.     }(this));

方法二

.thumbImage {max-width: 100px;max-height: 100px;} /* for Firefox & IE7 */
* html .thumbImage { /* for IE6 */
width: expression(this.width > 100 && this.width > this.height ? 100 : auto);
height: expression(this.height > 100 ? 100 : auto);

 

方法三

<div id="pic"><img src=http://www.cidianwang.com/images/zidian_s.gif /></div>
<script language="javascript">
var cfg = {
 maxWidth  :  480,
 maxHeight  :  480
} ;

lstImg = document.getElementById('pic').getElementsByTagName('img');
for (var i = 0; i < lstImg.length; i++) {
 var tmpW, tmpH;
 var img = lstImg[i];
 tmpW = img.width;
 tmpH = img.height;
 if (tmpW > cfg.maxWidth && tmpH > cfg.maxHeight) {
  if (tmpW / cfg.maxWidth > tmpH / cfg.maxHeight) {
   img.width = cfg.maxWidth;
   img.height = cfg.maxHeight * (cfg.maxWidth / tmpW);
  }
 }
 else {
  if (tmpW > cfg.maxWidth) {
   img.width = cfg.maxWidth;
   img.height = cfg.maxHeight * (cfg.maxWidth / tmpW);
  }
  else if (tmpH > cfg.maxHeight) {
   img.height = cfg.maxHeight;
   img.width = cfg.maxWidth * (cfg.maxHeight / tmpH);
  }
 }
}

</script>

标签:自动缩小,图片,兼容
0
投稿

猜你喜欢

  • asp函数收藏

    2009-04-21 13:10:00
  • 教你制作IBM LOGO的方法

    2007-10-23 13:34:00
  • 细化解析:SQL Server 2005 数据库镜像

    2009-01-23 13:41:00
  • 模拟兼容性的 inline-block 属性

    2008-04-08 12:37:00
  • PHP程序员最常犯的11个MySQL错误

    2012-01-05 19:13:02
  • { hide_text } CSS文字隐藏总结报告

    2010-06-13 17:19:00
  • 详尽解析javascript的event对象

    2008-01-16 11:27:00
  • 用ASP判断客户端浏览器语言自动跳转

    2010-07-09 13:34:00
  • MySQL 索引详解

    2010-01-20 09:39:00
  • sqlserver 三种分页方式性能比较[图文]

    2011-09-30 11:16:20
  • 配置SQL Server文件组对应不同的RAID系统

    2009-01-04 14:31:00
  • 创意设计:字母趣味组合

    2008-01-26 18:50:00
  • asp fso创建与删除文件与文件夹

    2008-12-31 16:07:00
  • SQL Server和Oracle并行处理方法对比

    2009-01-20 15:48:00
  • ASP获取ACCESS数据库表名及结构的代码

    2011-04-15 10:50:00
  • 用书的概念理解小网站结构

    2007-10-31 18:08:00
  • 定位后无法选择容器内容解决方案

    2008-07-28 13:14:00
  • WML初级教程之从实际应用中了解WML

    2008-09-04 11:24:00
  • 正确使用字体和颜色 让网页内容更易阅读

    2007-09-13 18:45:00
  • 数据库安全应用 使用MySQL的23个注意事项

    2009-05-13 10:27:00
  • asp之家 网络编程 m.aspxhome.com