Performance: Route transition animations
This affects the smoothness and responsiveness of page transitions during route changes, impacting user interaction and visual stability.
Jump into concepts and practice - no test required
import { trigger, transition, style, animate } from '@angular/animations'; @Component({ animations: [ trigger('routeAnimations', [ transition('* <=> *', [ style({ transform: 'translateX(100%)', opacity: 0 }), animate('300ms ease-out', style({ transform: 'translateX(0)', opacity: 1 })) ]) ]) ] }) export class AppComponent {}
import { trigger, transition, style, animate } from '@angular/animations'; @Component({ animations: [ trigger('routeAnimations', [ transition('* <=> *', [ style({ opacity: 0 }), animate('500ms ease-in-out', style({ opacity: 1 })) ]) ]) ] }) export class AppComponent {}
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Opacity animation without transform | Minimal DOM changes | No reflows triggered | High paint cost due to opacity changes | [X] Bad |
| Transform translateX with opacity | Minimal DOM changes | No reflows triggered | Low paint cost, GPU accelerated | [OK] Good |
trigger('routeAnimations', [
transition('* <=> *', [
style({ opacity: 0 }),
animate('300ms ease-in', style({ opacity: 1 }))
])
])
What happens when the route changes?@Component({
animations: [
trigger('routeAnimations', [
transition('HomePage => AboutPage', [
animate('500ms ease-in')
])
])
]
})
export class AppComponent {}