Performance: Why Angular animations matter
Angular animations affect the smoothness of user interactions and visual stability during page updates.
Jump into concepts and practice - no test required
animations: [trigger('fade', [state('void', style({opacity: 0})), transition(':enter', [animate('300ms ease-in', style({opacity: 1}))])])] // Limit animations to opacity and transform properties only, and throttle simultaneous animations
animations: [trigger('expand', [state('void', style({height: '0px'})), transition(':enter', [animate('500ms ease-in', style({height: '*'}))])])] // Using heavy animations on many elements simultaneously without throttling
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Animating layout properties (width, height, margin) | High - multiple nodes affected | Multiple reflows per frame | High paint cost due to layout changes | [X] Bad |
| Animating opacity and transform only | Low - no layout changes | No reflows triggered | Low paint cost, uses GPU compositing | [OK] Good |
trigger('fadeInOut', [
transition(':enter', [style({ opacity: 0 }), animate('500ms ease-in', style({ opacity: 1 }))]),
transition(':leave', [animate('500ms ease-out', style({ opacity: 0 }))])
])trigger('slideIn', [
transition('void => *', [style({ transform: 'translateX(-100%)' }), animate('300ms ease-in')])
])