如何修复 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/