首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用角度动画在单击时对图像进行动画处理

如何使用角度动画在单击时对图像进行动画处理
EN

Stack Overflow用户
提问于 2019-04-15 17:38:56
回答 2查看 156关注 0票数 3

此动画在页面加载时工作,但我需要在单击按钮时对此图像进行动画处理

代码语言:javascript
复制
<div [@fadeInDownOnEnter]="'true'">
    <img src="https://www.seoclerk.com/pics/556744-1wYpi51504622425.jpg" alt="animatepic">
</div>
<button (click)="animate()">Animate it</button>

在component.ts文件中

代码语言:javascript
复制
import { fadeInDownOnEnterAnimation } from 'angular-animations';
@Component({
  animations: [
    fadeInDownOnEnterAnimation()
  ]
})


//method 
animate(){
  //what should I do here
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-04-17 17:40:09

在您组件中,

代码语言:javascript
复制
    animationWithState = false;
    animate(){
    this.animationState=true;
    this.animationWithState = !this.animationWithState;
    }, 1);

代码语言:javascript
复制
<div [@fadeInDownOnEnter]="'true'">

这应该是这样的

代码语言:javascript
复制
<div [@fadeInDownOnEnter]="animationState">
票数 7
EN

Stack Overflow用户

发布于 2019-04-16 17:34:18

[@fadeInDownOnEnter]属性的值设置为将从组件中引用的变量,而不是模板中的静态值'true',如下所示

代码语言:javascript
复制
<div [@fadeInDownOnEnter]="animationState" >
  <img src="https://www.seoclerk.com/pics/556744-1wYpi51504622425.jpg" alt="animatepic">
</div>
<button (click)="animate()" >Animate it</button>

然后在您的组件中

代码语言:javascript
复制
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

}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55686369

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档