当前位置: 首页 > 图文教程 > 网络编程 > Javascript > js png图片(有含有透明)在IE6中为什么不透明了

Javascript
快速判断某个值是否在select中的方法
js-穷举法 (y0h)
彪哥1.1(智能表格)提供下载
prototype 1.5 & scriptaculous 1.6.1 学习笔记
IE中jscript/javascript的条件编译
prototype class详解
Javascript 事件捕获的备忘(setCapture,captureEvents)
showModelessDialog()使用详解
Mozilla中显示textarea中选择的文字
加入收藏夹代码(兼容 gecko)
b/s开发常用javaScript技术
一些有关检查数据的JS代码
Javascript 不能释放内存.
多附件上传组件演示
一个很Cool的JS菜单效果
打造个性化的Select(可编辑)
真正的连续滚动图片
js常用函数 不错
document.getElementById的一些细节
由浅到深了解JavaScript类

Javascript 中的 js png图片(有含有透明)在IE6中为什么不透明了


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2010-02-27   浏览: 113 ::
收藏到网摘: n/a

png-8模式的图片,如果没有渐变的话是透明的,如果有渐变就不透明了。需要js的支持。
复制代码 代码如下:

function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])
if ((version >= 5.5) && (document.body.filters)) {
for (var j = 0; j < document.images.length; j++) {
var img = document.images[j]
var imgName = img.src.toUpperCase()
if (imgName.substring(imgName.length - 3, imgName.length) == "PNG") {
var imgID = (img.id) ? "id='" + img.id + "' " : ""
var imgClass = (img.className) ? "class='" + img.className + "' " : ""
var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
var imgStyle = "display:inline-block;" + img.style.cssText
if (img.align == "left") imgStyle = "float:left;" + imgStyle
if (img.align == "right") imgStyle = "float:right;" + imgStyle
if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
var strNewHTML = "<span " + imgID + imgClass + imgTitle
+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
img.outerHTML = strNewHTML
j = j - 1
}
}
}
}
window.attachEvent("onload", correctPNG);