IE6.0及以下版本PNG透明图片不透明解决方案


/*
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.
Edit: Jena.want
Date: 2008.11.30
Web: www.AOBODO.com | www.IsHere.cn

Use in with DEFER keyword wrapped in conditional comments:

*/

(function fixPng() {
var arVersion = navigator.appVersion.split(“MSIE”)
var version = parseFloat(arVersion[1])

if ((version >= 5.5 && version < 7.0) && (document.body.filters)) {
for(var i=0; i
var img = document.images[i];
var imgName = img.src.toUpperCase();
if (imgName.indexOf(“.PNG”) > 0) {
var width = img.width;
var height = img.height;
var sizingMethod = (img.className.toLowerCase().indexOf(“scale”) >= 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”;
img.width = width;
img.height = height;
}
}
}
})();

这是打好包的文件,需要的朋友可以下载试试。msiepng

另外,如果PNG图片做背景的话,在IE6下也会出现不透明情况,以上脚本只解决了页面中的PNG图片透明,如果是CSS样式中使用了透明的PNG图片,则可以使用以下方案解决透明问题,利用了只有 IE6 才识别的下划线(_),来定义 IE6 浏览器中的滤镜:

#png {
background: url(绝对路径/images/bg.png) repeat;
_filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=’true’, sizingMethod=’scale’, src=”绝对路径/images/bg.png”);
_background:none;
}

Leave a Comment

Your email address will not be published.

*