角度4上的动画似乎没有过渡效果 [英] animation on angular 4 doesn't seem to have transition effect

查看:74
本文介绍了角度4上的动画似乎没有过渡效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

trigger('expandCollapse', [
            state('open', style({
                'height': '*'
            })),
            state('close', style({
                'height': '0px'
            })),
            transition('open <=> close', animate(1000))
        ])

使用此代码为展开塌陷进行动画处理,展开塌陷可以正常工作,但使用角动画框架4.3.1时高度上没有动画

using this code to animate expand collapse, the expand collapse works fine but there is no animation on height using angular animation framework 4.3.1

https://plnkr.co/edit/tY4z1QPvdKMeU6M82cTF?p=preview

为此创建了一个小型演示

created a small demo for the same

推荐答案

问题是NoopAnimationsModule.这有效:

//our root app component
import {Component, NgModule, VERSION} from '@angular/core'
import {BrowserModule} from '@angular/platform-browser'
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { trigger, state, style, transition, animate } from '@angular/animations';
@Component({
  selector: 'my-app',
  template: `
    <div>
    <button (click) ="openReportsFilter()">Open Close</button>
      <h2 [@expandCollapse] = 'openCloseAnim'>Hello {{name}}</h2>
    </div>
  `,
  animations: [
        trigger('expandCollapse', [
            state('open', style({
                'height': '*'
            })),
            state('close', style({
                'height': '0px'
            })),
            transition('open <=> close', animate(1000))
        ])
    ]
})
export class App {
  name:string;
  constructor() {
    this.name = `Angular! v${VERSION.full}`
    this.openCloseAnim = 'open';
  }
  openReportsFilter(): void {
        this.openCloseAnim = (this.openCloseAnim == 'open') ? 'close' : 'open';
    }
}

@NgModule({
  imports: [ BrowserModule,BrowserAnimationsModule ],
  declarations: [ App ],
  bootstrap: [ App ]
})
export class AppModule {


}

这篇关于角度4上的动画似乎没有过渡效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆