gpt4 book ai didi

angular - Angular 4 上的动画似乎没有过渡效果

转载 作者:太空狗 更新时间:2023-10-29 18:08:15 27 4
gpt4 key购买 nike

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

使用此代码为展开折叠设置动画,展开折叠工作正常,但使用 Angular 动画框架 4.3.1 高度没有动画

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

为此创建了一个小演示

最佳答案

问题是 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 {


}

关于angular - Angular 4 上的动画似乎没有过渡效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45467248/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com