ARTICLE AD BOX
I am working on a navigation toggle button for a website and I want to switch between two Material Design icons, menu and close, when the user clicks the button. Currently, the icon changes instantly without any animation. I would like to add a smooth transition effect so that the change between the two icons looks more visually appealing.
At the moment I am using Material Icons like this:
7,5793 gold badges34 silver badges42 bronze badges
New contributor
VIVEK TAWARE is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
1
The code you shared does not contain any Angular code. Kindly refer the Angular Docs and get familiar with Angular features.
We can use a signal Boolean called toggle and toggle this to add/remove the animate class and perform this effect.
TS:
import { Component, signal } from '@angular/core'; @Component({ selector: 'app-root', template: ` <span id="icon" class="material-icons" [class.animate]="toggle()" (click)="toggle.set(!toggle())"> {{toggle() ? 'menu' : 'close'}} </span> `, }) export class App { toggle = signal(false); }Stackblitz Demo
66.9k6 gold badges53 silver badges101 bronze badges
Explore related questions
See similar questions with these tags.
