Transparent PNG animate problem on Internet Explorer
CSS Code:
#btn{
background: url(transparent.png) no-repeat;
filter: alpha(opacity=0);
-moz-opacity: 0;
-khtml-opacity: 0;
opacity: 0;
}
JavaScript/jQuery:
$("#btn").animate({opacity:1,"margin-left":"-25px"});
I don't have any problem with the code above on Firefox, Chrome and others. But it does not work on any version of Internet Explorer.
The problem is the PNG image is rendered strange, background of the transparent PNG looks black. When I remove opacity effect, t开发者_如何学Pythonhere is no problem.
What is the solution?
For me it worked to just include the filter property with blank value in jQuery's .animate()function
Maybe this will work for you, too.
$("#btn").animate({opacity:1,"margin-left":"-25px", filter:''});
Additionally you might have to remove the filter property from your button's CSS.
filter:''
hack does not work with current jQuery (1.6.1) anymore
There is currently no solution for this that I'm aware of. Just have to wait for IE to catch up with the rest of the world. I had to abandon such a feature in a recent project just days ago. You unfortunately cannot have a feathered-edge PNG with IE fading in and out with jQuery.
Hey, looks like Sampson might have been wrong. See Dave Shea's post on this: http://mezzoblue.com/archives/2010/05/20/ie8_still_fa/
I'm just going to dump three paragraphs of the solution here:
Of course, no version of IE supports the CSS opacity property yet, so jQuery instead applies the opacity by exploiting the IE-proprietary
AlphaImageLoader
filter. This ends up being the root cause of the (seemingly well-known) bug. The suggested fix is to apply the transparency to the parent element instead, but I’ve had little success with that workaround.What did work was a little library called DD_belatedPNG that applies PNG transparency via VML instead of
AlphaImageLoader
. It’s designed for IE6, but it works just fine in IE7 as well. For IE8, I was forced to throw out an X-UA-Compatiblemeta
tag and step IE8 down to IE7 mode for this particular page.It’s still not perfect. I noticed a faint white bounding box poking through at lower opacities that forced me to slightly adjust hover effects for all versions of IE. But you know, for all that, it’s darn well good enough.
Mmmhmmm... It's odd that this solution didn't pop up when this question was asked 6 months ago. Sure, this blog post didn't exist, but the solution had been around for quite a while. Strange that nobody noticed it...
I think there is a real solution here : http://www.viget.com/inspire/jquery-ie-png-24-ie-black-background-issue-solved/
In my case it solved the awefull black bg on my animated png image with transparent background. It worked like a charm. Tested on ie7+ I can't test ie6 for the moment.
Hope it will help every one :) Julien
Use PNG image for modern Browsers ( mozilla , Opera, Chrome etc ) :
background:url(../images/banner01.png) no-repeat right 13px;
Add this For IE ( Use another CSS Or use IE hack )
/* ie fix */
background-image:none;
filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src="images/banner01.png",
sizingMethod="crop");
Interesting note: jQueryTOOLS uses a GIF in all IE versions as bugfix for tooltips. Demo
There is a library that supposedly solves this problem: jCSML. I have tried it and it works to animate transparent pngs in IE 7+.
HERE IS THE FIX! Update to the latest jQuery. Thats it. It works after that.
Thanks to Julien for his answer, it lead me in the right direction!
However, I was still getting a gray halo around the text during the image opacity transition. It looked fine when it was static, but it was still creating a strange slight grey halo (IE 8). I fixed it by changing to the values below.
Also, I had to separately declare the "zoom: 1" property, because IE 8 was just smashing that value to the end the background
property. Same thing with background-color: transparent;
IE sucks.
My working CSS:
.classOfParentElement img {
-ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr=#00FFFFFF,endColorstr=#FFFFFFFF)"; /* IE 8 */
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#00FFFFFF,endColorstr=#FFFFFFFF); /* IE 6 & 7 */
}
.classOfParentElement img {
-ms-zoom: 1;
zoom: 1;
background-color: transparent;
}
Note that I had to change endColorstr=#00FFFFFF
to endColorstr=#FFFFFFFF
.
To reiterate Julien, this solution came from Viget.com.
精彩评论