I have a css keyframe animation which loops.
animation-iteration-count: infinite
Now when I click a button I want the animation to finish the current loop and then stop.
this question seems related, but animationiteration webkitAnimationIteration callbacks don't seem to be called at the end of the keyframe animation, but more often.
EDIT: This turned out to almost be the correct solution, only that it can't handle multiple animations. For more info see my answer below.
This example shows my animation, and on hover I want to try to finish the current loop and then stop. This includes the answer proposed by @Alex Gru, It doesn't work if one wait for the animation to loop multiple times and then hover you can see the animation jumps. If it has not looped a full iteration and I set animation-iteration-count: 1 it works as intended.
document.getElementById("animated-thing").addEventListener("webkitAnimationIteration", function (event) {But the function is not called when the loop finished but more often in between.