I have two divs. One fills the page, the other is hidden and gets displayed with a CSS3 animation :
div{
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
}
.div2{
top:100%;
display:none;
transition: top 0.3s ease-in-out;
}
.div2.shown{
top:0;
}
Now, I know that I cannot put display:block directly inside the .shown class because it is not supported by CSS 3 animations.
So here is what I do :
$(".div2").show().toggleClass("shown");
But the animation does not work, it just appears instantly. I thought that it was because the .show() wasn't finished yet when I trigger toggleClass. So, as a "duration" method, it must support .delay.
Now, if I delay the toggleClass :
$(".div2").show().delay(100).toggleClass("shown");
Still does not work. Let's try a setTimeout:
$(".div2").show();
setTimeout(function(){$(".div2").toggleClass("shown")}, 1);
This one works. So it appears that show() is indeed a long operation, but it does not support the delay() method. So I wanted to try using its callback :
$(".div2").show(function(){$(".div2").toggleClass("shown")});
And this works, without setTimeout ! But the callback gets called twice (once at the beginning, once 400ms after). What should I use to do that properly ?