我正试图让一个带有fa图标的按钮旋转180度,然后在再次单击时反向旋转。到目前为止,我已经有了这个(在stackblitz中复制),但当点击按钮时,图标根本不会旋转。这可以通过CSS实现吗?还是我需要换一种方式?
烟囱闪电战:
https://stackblitz.com/edit/angular-ivy-5nbjjw?file=src%2Fapp%2Fapp.component.css
app.component.css
.expandButton:focus i {
animation: rotate 1s ease-in-out 0s;
}
@keyframes rotate {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
app.component.ts
import { Component, VERSION } from '@angular/core';
import { faChevronDown } from '@fortawesome/free-solid-svg-icons';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
})
export class AppComponent {
faChevronDown = faChevronDown;
}
app.component.html
<button class="expandButton" mat-raised-button color="primary" type="button">
<i><fa-icon [icon]="faChevronDown"></fa-icon></i>
</button>
app.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
import { PhotoGalleryComponent } from './components/photo-gallery/photo-gallery.component';
import {
FaIconLibrary,
FontAwesomeModule,
} from '@fortawesome/angular-fontawesome';
import { faChevronDown } from '@fortawesome/free-solid-svg-icons';
@NgModule({
imports: [
BrowserModule,
FormsModule,
PhotoGalleryComponent,
FontAwesomeModule,
],
declarations: [AppComponent],
bootstrap: [AppComponent],
})
export class AppModule {
constructor(library: FaIconLibrary) {
library.addIcons(faChevronDown);
}
}