height/width transition not working after hiding div
Hello,
I'm experimenting with CSS transitions. If you go to the follow site:
http://www.mm-theory.com/shahspace/w...ransition.html
you'll see what I've got so far.
What I've got is two div. On the left, you have a green div of which you can control the width with the buttons. On the right, you have a red div of which you can control the height with the buttons.
As you can see, growing and shrinking the divs works with CSS transitions.
The only thing which doesn't work (and this is what I need help with) is getting the transition to work when you go from hidden to a different size. So if you click the "hide" button, the div shrinks to nothing and disappears. But then if you click "small" it just reappears at the appropriate size (no transition).
I trust that you can get at the code at the site, but if not, let me know and I'll post it.
One thing that occurred to me was that maybe when you hide a div (using the jquery .hide() function), it sets the width/height to auto. In that case, calling .show() and then adding a class with a non-zero width/height may not result in a transition because how do you transition from auto to 100px (for example)?
To test that, I created this alternate version:
http://www.mm-theory.com/shahspace/w...ransition.html
In the javascript, instead of doing this:
$("#RightDiv").show();
$("#RightDiv").removeClass("bigHeightClass").removeClass("hiddenHeightClass");
$("#RightDiv").addClass("smallHeightClass");
I did this:
if ($("#RightDiv").css("display") == "none")
{
$("#RightDiv").show();
$("#RightDiv").height(0);
}
$("#RightDiv").removeClass("bigHeightClass").removeClass("hiddenHeightClass");
$("#RightDiv").addClass("smallHeightClass");
I was hoping that by setting the width to 0 right after calling .show() and then adding the appropriate class, the transition would occur. But it didn't work. In fact, it's even worse. Clicking "small" or "big" after hiding it only makes it visible but doesn't grow the width/height beyond 0.