31
Tips #2: Animating opacity with jQuery? Don’t forget to set your opacity before animating
Animating opacity with jQuery can be a little tricky. If you look closely, the first opacity animation might not happen. You would think that $(‘element’).animating({opacity:0}) would do the trick, but actually that is not really the case. When you animate opacity always remember to set the default opacity before, in CSS you can add opacity:0 to your element.
However, if you remember, Internet Explorer 6 and 7 do not support CSS opacity, they support the weird, IE only, filter:alpha(opacity=70). Unfortunately for us, that will not do the trick and the first opacity animation will not happen.
So there is only one cross browser way to do this that I know, in your DOM ready, add $(‘element’).css(“opacity”, 0).
Hope it helps!
1 Comment to “Tips #2: Animating opacity with jQuery? Don’t forget to set your opacity before animating”
Leave a comment
Articles
Some Tweets
- browseemall a nice solution for cross-browser testing http://t.co/b9ijFDqp
- Backbone.js 0.9 is kind of a nightmare for me, I see nothing in the changelog that should break my code but, lot of stuff are broken
- jQuery Mobile and backbone.js, the ugly http://t.co/Vi0UJlxe
- Instapaper Founder Marco Arment On The App Business http://t.co/HjiSYwjO
- CSS bug on ie8, only on windows xp, yay me, testing on a decade years old OS
- jQuery Mobile and backbone.js, the ugly http://t.co/Vi0UJlxe









thank you very much for this. it solved my problem in stupid ie6