Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 4 animate any height/position changes with angular animations

Pretty straight forward question I hope. Is there a way using angular animations syntax to animate any height or position changes on an element?

For example if a DOM element is removed causing another element to shift up, can the shift up be animated without having to set a state variable?

<div [@positionChange]></div>

Or something similar without state.

thanks in advance.

like image 474
rjustin Avatar asked Oct 27 '17 23:10

rjustin


People also ask

When using Angular animation what kind of transition do you need to use to animate the removal of an element?

However, we can use the style function within transitions and animations to define both the initial styling and also the final one, after the animation has been performed. To use this trigger from our component template we just need to attach it to a component that might get removed or added to the DOM.

What is the use of animateChild () function in Angular?

Each time an animation is triggered in Angular, the parent animation always gets priority and child animations are blocked. For a child animation to run, the parent animation must query each of the elements containing child animations. It then lets the animations run using the animateChild() function.

What is the benefit of Angular animation?

Overall, the angular animation framework allows you to create animations that have the same native performance as pure CSS animations. The benefit is that you can easily add and control animations at the component level.” In addition, the ability to run code before and after animation is a plus.


1 Answers

you could just add a fold-animation to all the child elements that might be removed / added dynamicly. If the child height is animated, the container size is animated anyway.

trigger('fold', [
  transition(':enter', [style({height: 0, overflow: 'hidden'}), animate('.3s ease', style({height: '*'}))]),
  transition(':leave', [style({height: '*', overflow: 'hidden'}), animate('.3s ease', style({height: 0}))])
]);
like image 169
Martin Cremer Avatar answered Nov 11 '22 19:11

Martin Cremer