I am animating a block with a key frame, then running reverse animation in javascript, for example:
$('#block').removeClass('animate1').addClass('animate2');
With animate1 and animate2 corresponding to the two CSS classes causing the animation (just for demonstration, only in webkit) and #block simple div :
CSS
.animate1 { -webkit-animation: shift 1s ease-in-out forwards; } .animate2 { -webkit-animation: shift 1s ease-in-out backwards reverse; } @-webkit-keyframes shift { from { left: 0px; } to { left: 200px; } }
HTML
<div id="block" class="animate2"></div>
It just doesn't work. See this script for a demo (Chrome 30).
Data
If I run the animation the other way around, I mean the reverse first, then normal, it works correctly ( demo )
$('#block').removeClass('animate2').addClass('animate1');
It also works if I delete the current class and add the next class with independent functions caused by clicking on the buttons.
Can someone help me understand this strange behavior? I am stuck!
Edit
For future visitors, I'm no longer looking for a workaround, just trying to figure out what is going on here:
- What is this "w70> time" required by the browser?
- Why does this work in some way and not in another?
- Why is animation running inside the inner closure?
If necessary, change the accepted answer.
source share