IE6 PNG 透明度 [英] IE6 PNG transparency
问题描述
如何修复 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>
将以下条件注释放在底部(页脚部分,就在之前