I'm trying to use animate()
to change the height and opacity of a div
. The div has an image background in CSS. It works fine on Firefox and Safari, but when I test it in IE the background is being removed. This is my code:
if (jQuery.support.opacity) {
jQuery('#list_box').animate({opacity: '1',height: '300px',top: newTop},{duration: 300});
} else {
jQuery('#list_box').animate({filter: 'alpha(opacity=100)',height: '300px',top: newTop},{duration: 300});
}
How can I fix this problem?
I've been having the same problem. I stumbled into the answer, when I set the opacity to 40%:
I noticed that made the opacity jump to 100%, then animate down to 40%. Eureka.
So, now I explicitly set the opacity to zero before the animation:
That animates smoothly, except the text still looks horrible in IE.
To clean up the text, I removed the opacity from the css in IE after the animation. This seems to clear up the text quite a bit in IE6 and IE8.
I'm testing it on a Mac in Parallels, in IE6 and IE8. Everything seems to work fine on the Mac side.
You do not need to write a special handler for IE, jQuery does it all for you behind the scenes:
HOWEVER: If you have a 24-bit transparent PNG as your background image that is disappearing, you need to be aware that you cannot combine
filter: alpha
(which jQuery correctly uses behind the scenes in IE) with a 24-bit transparent PNG in IE7 or IE8. I believe the only way around it is to set a background color (other thantransparent
) on the object on which you are usingfilter: alpha
How to test: Simply set a background color on
#list_box
to a solid color by adding something like this to your CSS after yourbackground-image
declaration:If the background image remains, and your
#list_box
animates correctly (except for the hideous background) you know what the problem is and will have to find another way to accomplish what you want.I was under the impression that jQuery did the whole opacity support thing for you. Does this work for all browsers?
I had the same sort of issue with this:
I simply added float:left; to the #nav li css and it fixed the issue.
I´ve had the same problem with the IE 7, the problem was a trailing comma after the opacity property
It has to be:
In jQuery, once the div is set to have either opacity:0 (in Standards Compliant Browsers) or filter:alpha(opacity=0) in IE, you can just use
Since jQuery supports cross-browser support, if you end up animating the filter via IE, then chances are jQuery is trying to support IE and the conflict comes when jQuery fires the opacity change x2.I hope this helps. I have had the same issue, plus odd issues with IE not being able to handle fading on a div stack with multiple items in it.