I am trying to make an animation play reverse when hovering an element. It does not work, I don't understand why and how to get it to work. The "animation" just jumps back to keyframe 0% without any animation.
The snippet works only as intended in Chrome and Safari.
http://codepen.io/anon/pen/YpBaZq
div {
-webkit-animation-fill-mode: forwards;
animation-duration: 2s;
animation-name: a;
background-color: #a00;
display: inline-block;
padding: 50px;
}
div:hover {
-webkit-animation-fill-mode: backwards;
animation-duration: 2s;
animation-name: a;
animation-direction: reverse;
}
@keyframes a {
0% {
padding: 50px;
}
100% {
padding: 100px 200px;
}
}
<div></div>
This is just an extremely simplified example, so please don't suggest non-animation methods (except maybe an animation combined with a transition on :hover
which I tried and couldn't get to work either).
This is much closer to the real-world code: https://codepen.io/connexo/pen/eBxMqO
I am also not interested in Javascript-based solutions, only CSS.