IE6 PNG 透明度 [英] IE6 PNG transparency

查看:38
本文介绍了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 Header 或其他现有的 .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>

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

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天全站免登陆