Iam trying to rotate an element once, but scale the element back and forth in an infinite loop. However, when I chain the two animations, only the last one runs. How do I make two different animations to work together?
.shape{
width:100px;
height:50px;
background-color: brown;
}
.ani1{
animation: scale 2s linear infinite alternate, rotate 5s ease forwards;
}
@keyframes rotate {
0%{
transform: rotate(0deg);
}
100%{
transform: rotate(360deg);
}
}
@keyframes scale {
0%{
transform: scale(1)
}
100%{
transform: scale(2)
}
}
<div class="shape ani1"></div>
2
Answers
To achieve the desired effect of rotating the element once and then scaling it back and forth in an infinite loop, you need to make a few adjustments to your CSS and animation definitions. One way to accomplish this is by using keyframes for both the rotation and scaling animations and then combining them in a single animation definition. Here’s the updated CSS code:
On modern browsers CSS property scale is implemented so you could keep your current structure but use that instead of transform.