Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS3 Transitions with toggleClass

I have the -webkit-transition-duration property set on a div, whose height is set by another class. When I use jQuery to toggle the class, it the transition does something funky.

It goes all the way up, and then is set to the proper height instead of just moving from 50px height to automatic height which is what I expect it to do. What's the fix for this?

Here is a demo: http://jsfiddle.net/XcFxQ/1/

like image 240
Q2Ftb3k Avatar asked Nov 20 '11 22:11

Q2Ftb3k


2 Answers

This works:

http://jsfiddle.net/Eric/XcFxQ/2/

Although the height is not strictly auto. It manually sets the height in order to make it animate.

like image 116
Eric Avatar answered Sep 25 '22 13:09

Eric


I was able to get it to work correctly without -webkit-transition-property and instead using jQuery 1.7 with jQuery UI as in this fiddle:

http://jsfiddle.net/pjFAt/

In my testing, this produced the cleanest, most robust results.

Now, I'm not sure if you're keen on including jQuery UI in your webpage. If not, it's my best guess that you might have to work around the rendering flaws using some more Javascript (ie. if hasClass, then animate, etc...)

like image 26
Matt Avatar answered Sep 21 '22 13:09

Matt