Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular page transition animation of specific items

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.

like image 323
Eduard Stankovič Avatar asked Nov 07 '22 09:11

Eduard Stankovič


1 Answers

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'
    }
  }
]
like image 163
Tomasz Kula Avatar answered Nov 15 '22 12:11

Tomasz Kula