PNG IE6 BUG解决方案

一:对于直接插入的图片,例如<div class=”pic”><img src="images/topic_03.png" /></div>请在<head></head>中插入以下JS代码,整个页面内的所有直接插入的png图片都可以实现透明:

<script language="JavaScript">
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);
</script>

二:对于使用css的background属性:

只能用CSS的Alpha滤镜解决,但是会发现在FF下不会出现背景,是由于FF不支持该滤镜的,所以利用CSS的hack区分属性,来解决同时为了节省代码,只在#main_pic中写公共属性

                              

                              

#main_pic{

            background-repeat:no-repeat;

                            height:200px;

                            width:200px;

                            }

 

html>body #main_pic{

    background:url(images/opacity.png) no-repeat;

}

                     

*#main_pic {

    background:none;

    filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='images/opacity.png', sizingMethod='crop');

}

其他牛人解决方案:彬的相关技术文章

你可能感兴趣的:(解决方案)