You could just use jQuery's sliedUp()
and slideDown()
:
$(document).ready(function(){
$(".singleAccordion").on("click", function(){
$(this).siblings().children(".content").slideUp();
$(".content", this).slideDown();
});
});
with following CSS:
.content{
overflow: hidden;
max-height: 500;
display: none;
}
Let me try to give some explanation.
Usually both transitions should run (pretty much) at the same time. If you replace max-height
with just height
(in your original code) you can see that that's actually the case. But for max-height
this seems to be different. I don't know why this is the case but I'd guess that it might be hard to derive the actual height that has to be applied while other transitions are running on the same DOM subtree and so it's just getting queued.
I'll take a look at some docs to see what's the reason behind this. Will report back if I find more intel.
Alright, I digged a little deeper. It really seems like the calculation of the actual height is the issue. Take your above code and replace max-height: 500px
with max-height: 5000px
. You'll see that it takes reeeaally long until the collapse happens. Now put max-height: 50px
in there and they will appear to happen at the same time.
Maybe this is because it's still animating beyond the actually required height. Sadly you can't animate onto height: auto
- most probably for quite the same reason.