I have a simple react app with a div containing an SVG ball image. Upon hovering on the image, I want it to rotate and move left simultaneously smoothly. When hover state is false, I want it to rotate and roll back to its initial position.
I'm struggling to combine both effects in CSS.
BallRoll.js
<div className="ball-holder">
<img
src={rollingBall}
loading="lazy"
width="223"
alt="rolling Ball"
className="ball"
/>
</div>
I'm a bit lost on the css, can't figure out a proper way to combine everything. ball.css
.ball {
display: block;
transition: 1s ease-in-out;
}
.ball:hover {
animation: animate2 5s linear;
}
@keyframes animate2 {
0%{
transform: rotate(0deg);
left:0;
}
50%{
transform: rotate(360deg);
left:calc(100% - 50px);
}
100%{
transform: rotate(0deg);
left:0;
}
They are not perfect, work fine individually, but not together. Any better suggestions and help?