Angular 5: animation of attenuation during routing (CSS)

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:

<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 for the page transition occurs in two stages (sequential):

  • page1 disappears (300 ms)
  • AND THEN page2 appears (300 ms)

I want the disappearance of page1 to occur simultaneously with the appearance of page2, the transitions must occur simultaneously.

Problem:

I want to prevent the TEMPORARY EXPLOSION of the contents of page1 or page2.

Explanation:

When an animation with a group (), to make them appear, disappears at the same time. And, temporarily setting the position to “absolute”, the content changes (because the content is 100% wide, and when the container is resized, the content also changes).

z-index:

position: 'relative', 'z-index': 1

, , .

?

+4
2

, , :

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 }
            )
        ])
    ])
]);

CSS :

/deep/ router-outlet~* {
    position: absolute;
    width: 100%;
    height: 100%;
}
+2

.

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 }))
    ]),
  ]);
+2

Source: https://habr.com/ru/post/1690754/


All Articles