I have a cog icon that I want to spin clockwise 180deg when activated (class="cards__cog cards__cog-active") and then spin another 180deg clockwise to return to its deactivated state (class="cards__cog cards__cog-inactive"). I am doing this with React, reacting to a change in the state when the cog is clicked.
The below works but my problems are:
1) It animates on page load (which makes sense because it has the cards__cog-inactive class but what is the alternative?).
2) It is ugly and there must be an easier way.
Thank you
.cards {
&__cog {
position: absolute;
right: 20px;
top: 20px;
width: 10vh;
cursor: pointer;
&-active {
animation: rotate180 1s ease;
animation-fill-mode: forwards;
}
&-inactive {
animation: rotate180to359to0 1s ease;
animation-fill-mode: forwards;
}
}
}
@keyframes rotate180 {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(180deg);
}
}
@keyframes rotate180to359to0 {
0% {
transform: rotate(180deg);
}
99% {
transform: rotate(359deg);
}
100% {
transform: rotate(0deg);
}
}