I want to animate a scale-down-then-scale-back effect on every button clicks. Here are what I tried:
<button (click)="clickMe()" [ngClass]="{'animated-button': animated}">Button</button>
Here's my CSS:
@keyframes buttonClickAnimation {
0% {transform: scale(0.8);}
100% {transform: scale(1);}
}
.animated-button {
animation: buttonClickAnimation 0.5s;
}
Here's my component:
...
animated: boolean = false;
clickMe() {
this.animated = true;
}
This only works on the very first click, which makes sense because my animated variable never gets set back to false. However, if I set it back to false in clickMe(), the animation wouldn't have time to execute. Maybe this isn't even the right way to implement this. Please advise! Thank you.