5

I would like to make route transition, but not simple slide out/slide in animations. I am looking for animation like this one on left ( https://cdn.dribbble.com/users/495792/screenshots/3847874/allshots3.gif )

I know how to animate routes that will redraw whole content. But how can I achieve effect of transitioning of one/more component to another (this enlarge /zoom effect on left) with changing route.

I would appreciate any advice or direction where to look for some sample codes.

  • You can create a custom animation with the desired `enter` and `leave` effects and add it to each element that need to be animated. I wonder if angular will wait for animation to complete before transitioning to next route. – sabithpocker Mar 22 '18 at 17:02

1 Answers1

1

You should read up on Routable Animations. Check out this blog post by Matias Niemelä (guy responsible for @angular/animations).

new-wave-of-animation-features

TL;DR:

<!-- app.html -->
<div [@routeAnimation]="prepRouteState(routerOutlet)">
    <!-- make sure to keep the ="outlet" part -->
  <router-outlet #routerOutlet="outlet"></router-outlet>
<div>


// app.ts
@Component({
  animations: [
    trigger('routeAnimation', [
      // no need to animate anything on load
      transition(':enter', []),
      // but anytime a route changes let's animate!
      transition('homePage => supportPage', [
        // ... some awesome animation here
      ]),
      // and when we go back home
      transition('supportPage => homePage', [
        // ... some awesome animation here
      ])
    ])
  ] 
})
class AppComponent {
  prepRouteState(outlet: any) {
    return outlet.activatedRouteData['animation'] || 'firstPage'; 
  }
}

<!-- app-routing.module.ts -->
const ROUTES = [
  { path: '',
    component: HomePageComponent,
    data: {
      animation: 'homePage'
    }
  },
  { path: 'support',
    component: SupportPageComponent,
    data: {
      animation: 'supportPage'
    }
  }
]
Dani
  • 3,128
  • 2
  • 43
  • 91
Tomasz Kula
  • 16,199
  • 2
  • 68
  • 79