internet-explorer - IE6 PNG 透明度

标签 internet-explorer png internet-explorer-6 transparency

如何修复 IE6 中背景图像的 PNG 透明度错误?

最佳答案

我喜欢这个由 David Cilley 编写的 Javascript 解决方案前一段时间。它摆脱了兼容浏览器的束缚,可以与您想要的任何后端一起使用。尽管如此,它仍然需要一个空白的 gif 图像。

将这些函数添加到您的 HTML Header 或其他现有 .js 中,包括:

<script type="text/javascript">
    function fixPngs(){
    // Loops through all img tags   
        for (i = 0; i < document.images.length; i++){
            var s = document.images[i].src;
            if (s.indexOf('.png') > 0)  // Checks for the .png extension
                fixPng(s, document.images[i]);
        }
    }

    function fixPng(u, o){
        // u = url of the image
        // o = image object 
        o.src = 'images/spacer.gif';  // Need to give it an image so we don't get the red x
        o.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + u + "', sizingMethod='scale')";
    }   
</script>

将以下条件注释放在底部(页 footer 分,就在之前

):
<!--[if lte IE 6]>
    <script language="javascript" type="text/javascript">
        //this is a conditional comment that only IE understands. If a user using IE 6 or lower 
         //views this page, the following code will run. Otherwise, it will appear commented out.
        //it goes after the body tag so it can fire after the page loads.
        fixPngs();
    </script> 
<![endif]-->

要更全面地了解 IE6 的奇怪之处,请尝试 IE7 Javascript library .

关于internet-explorer - IE6 PNG 透明度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/697682/

相关文章:

javascript - window.focus 在 IE 中不起作用

math - LaTeX 相当于 Google Chart API

jquery slider ie6 和 7 对齐问题

css - 选择菜单和 ie6 .. 再次

javascript - IE 不清除选择值

html - IF IE 条件语句不起作用

C# Win8 : copy . PNG到Windows剪贴板;粘贴并保留透明度

css - 网站中的 Logo 未在 IE 中显示

internet-explorer - 如何最好地说服人们升级 IE?

html - Flash swf 无法在 IE8 中播放