简体   繁体   中英

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.

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'
    }
  }
]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM