I am seeking a solution to rotate a cog icon clockwise by 180 degrees when activated with the class "cards__cog cards__cog-active" and then rotate another 180 degrees clockwise back to its deactivated state using the class "cards__cog cards__cog-inactive". In my React project, I am updating the state when the cog is clicked in order to achieve this animation.
Although the current code works, I have encountered some issues:
1) The animation triggers on page load due to the initial "cards__cog-inactive" class. Is there a better approach to prevent this?
2) The implementation feels cumbersome and could possibly be simplified. Are there any suggestions for improvement?
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);
}
}