解决ie6里png图片透明变白色bug

加入这段js就行了。

 1 function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
 2 {
 3     var arVersion = navigator.appVersion.split("MSIE")
 4     var version = parseFloat(arVersion[1])
 5     if ((version >= 5.5) && (document.body.filters))
 6     {
 7         for(var j=0; j<document.images.length; j++)
 8         {
 9             var img = document.images[j]
10             var imgName = img.src.toUpperCase()
11             if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
12             {
13                 var imgID = (img.id) ? "id='" + img.id + "' " : ""
14                 var imgClass = (img.className) ? "class='" + img.className + "' " : ""
15                 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
16                 var imgStyle = "display:inline-block;" + img.style.cssText
17                 if (img.align == "left")
18                     imgStyle = "float:left;" + imgStyle
19                 if (img.align == "right")
20                     imgStyle = "float:right;" + imgStyle
21                 if (img.parentElement.href)
22                     imgStyle = "cursor:hand;" + imgStyle
23                 var strNewHTML = "<span " + imgID + imgClass + imgTitle
24                     + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
25                     + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
26                     + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
27                 img.outerHTML = strNewHTML
28                 j = j-1
29             }
30         }
31     }
32 }
33 window.attachEvent("onload", correctPNG);

 

转载于:https://www.cnblogs.com/xzhang/p/3767835.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值