【问题标题】:Animation transition not working - angular 6动画过渡不起作用 - 角度 6
【发布时间】:2018-11-08 07:13:13
【问题描述】:

我需要在打开和关闭 Sidenav 时制作动画

    animations: [
    trigger('slider', [
      state('open', style(
        {}
      )),
      state('closed', style(
        {}
      )),
      transition('closed => open', animate('0.4s ease-in')),
      transition('open => closed', animate('0.4s ease-out'))      
    ])
  ]

...

  @Input('state') state: string = 'closed';


  toggleState() {
    this.state = this.state === 'open' ? 'closed' : 'open';
  }

  openSidenav() {
    this.opened = true;
    this.aux = 0;
    this.toggleState();
  }

  closeSidenav() {
    if (this.opened) {
      this.opened = !this.opened;
      this.toggleState();     
    }
  }

....

我的html

<div [@slider]="state" >
    <header> {{ navTitle }} </header>
    <i *ngIf="showCloseButton" class="iconic" (click)="closeSidenav()"></i>
    <ng-content></ng-content>
</div>

<div *ngIf="backdrop && opened" class="sidenav-backdrop"></div>

不显示任何错误只是不应用动画...我哪里出错了?

【问题讨论】:

  • 问题是每个过渡状态的所有样式都是空的
  • 我为样式添加了背景。他申请了。但是开合动画不起作用
  • 将0.4s更改为400ms,同时发布更新后的代码

标签: angular angular6 angular-animations angular-transitions


【解决方案1】:

我的问题在于动画。

  animations: [
    trigger('slider', [
      state('open', style(
        {
          transform: 'translateX(0)'
        }
      )),
      transition('void => open', [
        style({transform: 'translateX(-100%)'}),
        animate(300)
      ]),   
      transition('open => void', [
        animate(100, style({transform: 'translateX(-100%)'}))
      ])
   ]

【讨论】:

    猜你喜欢
    • 2018-10-22
    • 1970-01-01
    • 2014-06-28
    • 2015-05-28
    • 2012-04-18
    • 2016-09-22
    • 2018-02-28
    • 2019-06-10
    • 1970-01-01
    相关资源
    最近更新 更多