要在 在上面的代码中,我们定义了一个名为 在上面的代码中,我们在 在上面的代码中,我们使用 现在,当您点击元素上使用Angular动画,您可以按照以下步骤进行操作:
npm install @angular/animations --save
BrowserAnimationsModule
:import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
@NgModule({
imports: [BrowserAnimationsModule],
// other module configurations...
})
export class AppModule { }
trigger
,state
,style
和transition
等动画相关的函数和装饰器:import { trigger, state, style, transition, animate } from '@angular/animations';
@Component({
selector: 'app-your-component',
templateUrl: 'your-component.html',
styleUrls: ['your-component.css'],
animations: [
trigger('rowAnimation', [
state('fadeIn', style({ opacity: 1 })),
transition('void => *', [
style({ opacity: 0 }),
animate('500ms ease-in')
]),
transition('* => void', [
animate('500ms ease-out', style({ opacity: 0 }))
])
])
]
})
export class YourComponent {
// component logic...
}
rowAnimation
的触发器,它有两个状态:fadeIn
和void
。我们定义了从void
状态到任何状态的进入和退出过渡。
Row content
元素上使用了 [@rowAnimation]
绑定,并在click
事件中切换了rowAnimationState
状态。
export class YourComponent {
rowAnimationState = '';
toggleRowAnimation() {
this.rowAnimationState = this.rowAnimationState === 'fadeIn' ? '' : 'fadeIn';
}
}
toggleRowAnimation()
方法切换rowAnimationState
状态。元素时,动画将在进入和退出时应用。
相关内容