IE6 PNG透明度 [英] IE6 PNG transparency

查看:110
本文介绍了IE6 PNG透明度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How can I fix PNG transparency bug in IE6 for background image?

推荐答案

我喜欢这个由 David Cilley 。它不受兼容浏览器的限制,可以与您想要的任何后端一起使用。它仍然需要一个空白的GIF图像。

I like this Javascript solution writen by David Cilley some time ago. It gets out of the way of compliant browsers and can be used with any back-end you want. It does still require a blank gif image though.

将这些函数添加到HTML标题或其他现有.js包括:

Add these functions to your HTML Header or other existing .js include:

<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>

在底部放置以下条件评论(页脚部分,就在
< /之前) body>
):

Put the following conditional comment at the bottom (footer section, just before </body> ):

<!--[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库

For a more comprehensive approach to IE6 oddities, try the IE7 Javascript library.

这篇关于IE6 PNG透明度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆