在Internet Explorer中使用透明背景替换PNG图像

时间:2009-12-20 15:16:45

标签: jquery internet-explorer png background transparent

image1.png和image2.png都具有透明背景。

<script type="text/javascript">
    $(document).ready(function(){
        $("img#test").click(function() {
            $(this).attr("src", "image2.png");
        });
    });
</script>
<img id="test" src="image1.png">

上面的代码应该用image2.png替换image1.png。但是在Internet Explorer 6/7/8(兼容性视图关闭)中,它不会从背景中清除image1.png,而只是将image2.png放在image1.png上。

如何在替换为image2.png之前完全从背景中动态删除image1.png?

修改

我在base.css中使用以下代码修复了在Internet Explorer中显示tranparent .png图像的错误。

/ * Png Ransparent * /

.mypng img {

方位角:表达式(

this.pngSet?this.pngSet = true:(this.nodeName ==“IMG”&amp;&amp; this.src.toLowerCase()。indexOf('。png')&gt; -1?(this.runtimeStyle .backgroundImage =“none”,

this.runtimeStyle.filter =“progid:DXImageTransform.Microsoft.AlphaImageLoader(src ='”+ this.src +“',sizingMethod ='image')”,

this.src =“/ static / images / transparent.gif”):( this.origBg = this.origBg?this.origBg:this.currentStyle.backgroundImage.toString()。replace('url(“', '').replace( '“)', ''),

this.runtimeStyle.filter =“progid:DXImageTransform.Microsoft.AlphaImageLoader(src ='”+ this.origBg +“',sizingMethod ='crop')”,

this.runtimeStyle.backgroundImage =“none”)),this.pngSet = true);

}

这是导致这个问题的原因吗?

2 个答案:

答案 0 :(得分:1)

您可以尝试使用$(this).after();并在要替换的图像之后添加新图像;最后做$(this).remove();

答案 1 :(得分:0)

DD_belatedPNG替换.png修复代码后,以前的代码可以运行。

相关问题