Run multiple query animations in parallel

孤街浪徒 提交于 2019-12-23 07:40:09

问题


I have two routed components and their container to which I've set an animation trigger, @slide, wherein I query for each and animate accordingly.

<div [@slide]="o.activatedRouteData.name">
  <router-outlet #o="outlet"></router-outlet>
<div>

RouterModule.forRoot([
  { path: '',      component: HomeComponent,  data: { name: 'home' } },
  { path: 'login', component: LoginComponent, data: { name: 'login' } } ])

trigger('slide', [
  transition('login => home', [
    query('home', style({ left: '-120%', right: '120%' })),
    query('login', style({ left: '0', right: '0' })),

    query('home', animate(duration, style({ left: '0', right: '0' }))),
    query('login', animate(duration, style({ left: '120%', right: '-120%' })))
])

This works, except that the second animation waits for the first to complete before firing, while what I'm looking for is a way to have them fire in parallel. Thoughts?


回答1:


Wrap the queries in a group()

trigger('slide', [
  transition('login => home', [
    query('home', style({ left: '-120%', right: '120%' })),
    query('login', style({ left: '0', right: '0' })),

    group([ query('home', animate(duration, style({ left: '0', right: '0' }))),
            query('login', animate(duration, style({ left: '120%', right: '-120%' }))) ])
])

Credit to Ploppy3 over on GitHub.




回答2:


Ploppy3 answered you here: https://github.com/angular/angular/issues/9845#issuecomment-321240191 how to make separate animation for router on init. Child animation is disabled by default so you will see just router animation (to enable it you can check https://angular.io/api/animations/animateChild). So to do what you want I need just add animation you need for the components. So you need to add routerAnimation as Ploppy3 wrote and to use slide for components.



来源:https://stackoverflow.com/questions/45598685/run-multiple-query-animations-in-parallel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!