I have 2 routes :
export const appRoutes: Route[] = [
{
path: 'page1',
component: Page1Component,
data: {
animation: 'page1'
}
},
{
path: 'page2',
component: Page2Component,
data: {
animation: 'page2'
}
},
];
My Route animation :
export const routeStateTrigger = trigger('routeState', [
transition('* => *', [
query(':enter', [
style({ position: 'absolute', opacity: 0 })
], { optional: true }),
query(':leave', [
animate(300, style({ opacity: 0 }))
], { optional: true }),
query(':enter', [
style({ position: 'relative', opacity: 0 }),
animate(300, style({ display: 'visible', opacity: 1 }))
], { optional: true })
])
]);
My router-outlet :
<div [@routeState]="getAnimationData(routerOutlet)">
<router-outlet #routerOutlet="outlet"></router-outlet>
</div>
and getAnimationData method :
getAnimationData(routerOutlet: RouterOutlet) {
const routeData = routerOutlet.activatedRouteData['animation'];
return routeData ? routeData : 'rootPage';
}
This works well, except page transition occurs in two steps (sequential) :
What I want is the disappearing of page1 should happen the same time page2 appears, the transitions should occur simultaneously.
Problem :
I want to prevent the TEMPORARY RESIZING of the content of page1 or page2.
Explanation :
When animating with group() to make them appear-disappear simultaneously AND setting the position temporarily to 'absolute' then the content resizes (because the content is width 100%, and when the container size changes the content changes as well).
I've tried playing with z-index :
position: 'relative', 'z-index': 1
but that didn't work, it's still stacking entering page below leaving page.
Is there a good solution to this ?
I use CSS only to create fade animation during routing like this:
@keyframes fade {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
router-outlet + * {
display: block; /* Change display inline to block */
animation: fade 1s;
}
Note: I use global style, you can use more classes to isolate.
I finally made it work :
export const routeStateTrigger = trigger('routeState', [
transition('* => *', [
query(':enter', [
style({ opacity: 0 })
], { optional: true }
),
group([
query(':leave', [
animate(300, style({ opacity: 0 }))
],
{ optional: true }
),
query(':enter', [
style({ opacity: 0 }),
animate(300, style({ opacity: 1 }))
],
{ optional: true }
)
])
])
]);
This CSS selector did the trick :
/deep/ router-outlet~* {
position: absolute;
width: 100%;
height: 100%;
}
Try this simple transition.
export const routeStateTrigger =
// trigger name for attaching this animation to an element using the [@triggerName] syntax
trigger('routeState', [
// route 'enter and leave (<=>)' transition
transition('*<=>*', [
// css styles at start of transition
style({ opacity: 0 }),
// animation and styles at end of transition
animate('0.4s', style({ opacity: 1 }))
]),
]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With