【问题标题】:How to change states at the end of an animation transition? - Angular 2如何在动画过渡结束时更改状态? - 角 2
【发布时间】:2017-03-10 07:01:26
【问题描述】:

您好,我正在尝试让我的 Angular 2 应用程序进行路由器转换,如本教程所示。

Router Transition Tutorial

Demo Link

我对动画真的很陌生,并且在将组件样式留在 position:fixed 不允许滚动的状态下遇到问题。我想知道如何在 :entry 转换结束时将状态更改为用户定义的状态。

function slideToRight() {
  return trigger('routerTransition', [
    state('void', style({position:'fixed', width:'100%'}) ),
    state('*', style({position:'fixed', width:'100%'}) ),
    state('visible', style({position:'static', width:'initial'}) ),
    transition(':enter => visible', [ //<-- my attempt at switching the state
      style({transform: 'translateX(-100%)'}),
      animate('0.5s ease-in-out', style({transform: 'translateX(0%)'})),
    ]),
    transition('visible => :leave', [ //<-- my attempt at switching the state
      style({transform: 'translateX(0%)'}),
      animate('0.5s ease-in-out', style({transform: 'translateX(100%)'}))
    ])
  ]);
}

【问题讨论】:

  • 我终于明白fixed有什么问题了...呵呵=)

标签: angular animation typescript state


【解决方案1】:

尝试将 style 放在转换中。

slideToLeft 函数示例:

function slideToLeft() {
  return trigger('routerTransition', [
    transition(':enter', [
      style({transform: 'translateX(100%)', position:'fixed', width:'100%'}),
      animate('0.5s ease-in-out', style({transform: 'translateX(0%)'}))
    ]),
    transition(':leave', [
      style({transform: 'translateX(0%)', position:'fixed', width:'100%'}),
      animate('0.5s ease-in-out', style({transform: 'translateX(-100%)'}))
    ])
  ]);
}

【讨论】:

  • 谢谢!它修好了! :)
猜你喜欢
  • 2012-07-07
  • 1970-01-01
  • 2016-02-23
  • 2018-09-19
  • 1970-01-01
  • 2019-10-17
  • 2017-05-03
  • 1970-01-01
  • 2023-04-04
相关资源
最近更新 更多