Performance: Keyframe animations
MEDIUM IMPACT
Keyframe animations affect the smoothness of visual transitions and can impact the browser's paint and composite stages, influencing user experience during animations.
import { animate, keyframes, style, transition, trigger } from '@angular/animations'; export const slideAnimation = trigger('slide', [ transition(':enter', [ animate('500ms ease-in', keyframes([ style({ transform: 'translateX(0)', offset: 0 }), style({ transform: 'translateX(100px)', offset: 1 }) ])) ]) ]);
import { animate, keyframes, style, transition, trigger } from '@angular/animations'; export const slideAnimation = trigger('slide', [ transition(':enter', [ animate('500ms ease-in', keyframes([ style({ left: '0px', offset: 0 }), style({ left: '100px', offset: 1 }) ])) ]) ]);
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Animating 'left' property | Multiple style updates | Triggers reflow every frame | High paint cost due to layout changes | [X] Bad |
| Animating 'transform' property | Style updates only | No reflows triggered | Low paint cost, uses compositor | [OK] Good |