此动画在页面加载时工作,但我需要在单击按钮时对此图像进行动画处理
<div [@fadeInDownOnEnter]="'true'">
<img src="https://www.seoclerk.com/pics/556744-1wYpi51504622425.jpg" alt="animatepic">
</div>
<button (click)="animate()">Animate it</button>在component.ts文件中
import { fadeInDownOnEnterAnimation } from 'angular-animations';
@Component({
animations: [
fadeInDownOnEnterAnimation()
]
})
//method
animate(){
//what should I do here
}发布于 2019-04-17 17:40:09
在您组件中,
animationWithState = false;
animate(){
this.animationState=true;
this.animationWithState = !this.animationWithState;
}, 1);和
<div [@fadeInDownOnEnter]="'true'">这应该是这样的
<div [@fadeInDownOnEnter]="animationState">发布于 2019-04-16 17:34:18
将[@fadeInDownOnEnter]属性的值设置为将从组件中引用的变量,而不是模板中的静态值'true',如下所示
<div [@fadeInDownOnEnter]="animationState" >
<img src="https://www.seoclerk.com/pics/556744-1wYpi51504622425.jpg" alt="animatepic">
</div>
<button (click)="animate()" >Animate it</button>然后在您的组件中
import {fadeInDownOnEnterAnimation} from 'angular-animations';
@Component({
animations:[
fadeInDownOnEnterAnimation()
]
})
animationState = 'true';
//method
animate(){
//what should I do here
this.animationState = this.animationState === 'true' ? 'false' : 'true';
// the code above will toggle the value of animationState between 'true' and 'false'
// in order to update the animation
}https://stackoverflow.com/questions/55686369
复制相似问题