Performance: Animate method for timing
MEDIUM IMPACT
This affects how smoothly animations run and how quickly the page responds during animation sequences.
import { animate, style, transition, trigger } from '@angular/animations'; import { Component } from '@angular/core'; @Component({ animations: [ trigger('fadeIn', [ transition(':enter', [ style({ opacity: 0 }), animate('500ms ease-in-out', style({ opacity: 1 })) ]) ]) ] }) export class MyComponent {}
import { animate, style, transition, trigger } from '@angular/animations'; import { Component } from '@angular/core'; @Component({ animations: [ trigger('fadeIn', [ transition(':enter', [ style({ opacity: 0 }), animate('500ms linear', style({ opacity: 1 })) ]) ]) ] }) export class MyComponent {}
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Linear timing on multiple properties | Multiple style changes | Multiple reflows | High paint cost | [X] Bad |
| Ease-in-out timing on opacity only | Minimal style changes | Single reflow | Low paint cost | [OK] Good |