If I have keyframe animation running on an div hover (say, for 3s) and the element hover ends in 2 seconds, the animation abruptly ends and resets the div position. Here's an example, I am rotating a div on hover to 360 degrees in 3 seconds. If I hover out within two seconds, the animation ends abruptly.
I want the animation to reverse from the exact angle it had been rotated to. (See demo below)
How do I prevent the element to reset to its original position and start reversing the animation from the rotated angle, back to its original position.
.box {
width : 160px; height : 160px; background-color : green;
}
.box:hover {
-webkit-animation: move 3s;
}
@-webkit-keyframes move {
0% { -webkit-transform: rotate(360deg); }
100% { -webkit-transform: rotate(0deg); }
}
<div class ="box"></div>
I believe it needs to be done with some JS/jQuery using the mouseout event but I don't know exactly how to achieve this.
Help would be appreciated.