2
Here is an example. The main point is to animate a pseudo-element in the :hover
of div
father. Thus you avoid to rotate directly the father and then the son too. Moreover in the interection-count
of animation
you put the value of 3
to rotate only 3x and then stop, ie 3 turns in 3 seconds (each spinner has 1s and since 3 spins totals 3 seconds, I left comments in the code). To give the appearance of spin of load just vc put one of the edges with transparent color, I used border-bottom-color: transparent;
to give that effect.
Follow the image code above.
.icon {
display: flex;
justify-content: center;
align-items: center;
position: relative;
width: 48px;
height: 48px;
}
.icon::after {
content: "";
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
box-sizing: border-box;
border: 5px solid #000;
border-radius: 50%;
}
.icon:hover::after {
animation: gira 1s linear; /* 1s é o tempo da animação de cada giro */
animation-iteration-count: 3; /* 3 é a quantidade de giros, 3 giros = 3 segundos */
}
@keyframes gira {
0% {
transform: rotate(0deg);
border-bottom-color: transparent;
}
100% {
border-bottom-color: transparent;
transform: rotate(360deg);
}
}
<div class="icon">
<img src="https://placecage.com/24/24">
</div>
Show also the HTML of the element.
– Sam