I add two animation to one element. One is to rotate 360deg and one is to drag it some pixels towards x-axis using translate() method . But when I run it the element don’t 360deg correctly. It’s rotate some degree and suddenly change to another without animate .
I try to do one rotate and move it certain pixels towards x-axis . But rotation is not smooth.
2
Answers
To apply two animations to one element and ensure they both work well together, you can utilize CSS keyframes and animation properties. Here’s an example of how you can achieve this:
In this example, we define two keyframes animations:
rotate
andtranslate
. Therotate
animation rotates the element 360 degrees continuously over a duration of 4 seconds. Thetranslate
animation moves the element horizontally by 100 pixels and then back to its original position over a duration of 2 seconds. Theinfinite
keyword is used to make both animations repeat indefinitely.By applying both animations to the same element using the
animation
property, you can achieve simultaneous and synchronized animations.Adjust the animation properties, keyframe percentages, and animation durations as needed to match your desired effects.