So, it is possible to have reverse animation on mouse out such as:
.class{
transform: rotate(0deg);
}
.class:hover{
transform: rotate(360deg);
}
but, when using @keyframes animation, I couldn't get it to work, e.g:
.class{
animation-name: out;
animation-duration:2s;
}
.class:hover{
animation-name: in;
animation-duration:5s;
animation-iteration-count:infinite;
}
@keyframe in{
to {transform: rotate(360deg);}
}
@keyframe out{
to {transform: rotate(0deg);}
}
What is the optimal solution, knowing that I'd need iterations and animation itself?
creating a reversed animation is kinda an overkill to a simple problem, what u need is
however this wont work on its own because animation spec is so dump that they forgot to add a way to restart the animation so here is how you do it with the help of js
I think that if you have a
to
, you must use afrom
. I would think of something like :Of course must have checked it already, but I found strange that you only use the
transform
property since CSS3 is not fully implemented everywhere. Maybe it would work better with the following considerations :@-webkit-keyframes
, no particuliar version needed@-webkit-keyframes
since version 5+@keyframes
since version 16 (v5-15 used@-moz-keyframes
)@-webkit-keyframes
version 15-22 (only v12 used@-o-keyframes
)@keyframes
since version 10+EDIT :
I came up with that fiddle :
http://jsfiddle.net/JjHNG/35/
Using minimal code. Is it approaching what you were expecting ?
I don't think this is achievable using only CSS animations. I am assuming that CSS transitions do not fulfil your use case, because (for example) you want to chain two animations together, use multiple stops, iterations, or in some other way exploit the additional power animations grant you.
I've not found any way to trigger a CSS animation specifically on mouse-out without using JavaScript to attach "over" and "out" classes. Although you can use the base CSS declaration trigger an animation when the :hover ends, that same animation will then run on page load. Using "over" and "out" classes you can split the definition into the base (load) declaration and the two animation-trigger declarations.
The CSS for this solution would be:
And using JavaScript (jQuery syntax) to bind the classes to the events:
Its much easier than all this: Simply transition the same property on your element
https://codepen.io/lafland/pen/MoEaoG
Would you be better off having just the one animation, but having it reverse?
Try this:
supported in Firefox 5+, IE 10+, Chrome, Safari 4+, Opera 12+