I\'m trying to use ng-animate
to get a behavior similar to JQuery\'s slideUp()
and slideDown()
. Only I\'d rather use ng-show
This can actually be done in CSS and very minimal JS just by adding a CSS class (don't set styles directly in JS!) with e.g. a ng-click
event. The principle is that one can't animate height: 0;
to height: auto;
but this can be tricked by animating the max-height
property. The container will expand to it's "auto-height" value when .foo-open
is set - no need for fixed height or positioning.
.foo {
max-height: 0;
}
.foo--open {
max-height: 1000px; /* some arbitrary big value */
transition: ...
}
see this fiddle by the excellent Lea Verou
As a concern raised in the comments, note that while this animation works perfectly with linear easing, any exponential easing will produce a behaviour different from what could be expected - due to the fact that the animated property is max-height
and not height
itself; specifically, only the height
fraction of the easing curve of max-height
will be displayed.