摘自: http://www.cbmland.com/post/376/transparent-png-in-ie6-utility.html

做Web开发的朋友一定都知道PNG是一个相当不错的图片格式,但是这个好的格式却在IE6时代造成了麻烦,IE6会使透明的PNG的透明部分出现#DBEAED的色彩。透明不了。使得在FF下开发表现很好的界面换成IE浏览就惨不忍睹,又逼着换成GIF,而GIF的假透明在变换背景时造成毛边现象。

 刚去了www.gowindowslive.com去生成一个WLM的联系方式图标,结果发现的官方的解决方案。;)

核心函数贴出来供分析



 
/*
Correctly handle PNG transparency in Win IE 5.5 & 6.
Copyright 2007 Ignia, LLC
Based in part on code from from http://homepage.ntlworld.com/bobosola.
 
Use in  with DEFER keyword wrapped in conditional comments:
 
<script type="text/javascript" defer="true" src="pngfix.js"></script>
 
*/

 
function fixPng() {
  var arVersion = navigator.appVersion.split("MSIE")
  var version = parseFloat(arVersion[1])
 
  if ((version &gt;= 5.5 &amp;&amp; version &lt; 7.0) &amp;&amp; (document.body.filters)) {
    for(var i=0; i<document.images.length;></document.images.length;>      var img = document.images[i];
      var imgName = img.src.toUpperCase();
      if (imgName.indexOf(".PNG") &gt; 0) {
        var width = img.width;
        var height = img.height;
        var sizingMethod = (img.className.toLowerCase().indexOf("scale") &gt;= 0)? "scale" : "image";
        img.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + img.src.replace('%23', '%2523').replace("'", "%27") + "', sizingMethod='" + sizingMethod + "')";
        img.src="images/blank.gif" mce_src="images/blank.gif";
        img.width = width;
        img.height = height;
        }
      }
    }
  } 
 
posted on 2008-04-04 21:10  袁礼定  阅读(1030)  评论(0编辑  收藏  举报