Reputation: 145
i'm applying a css keyframe animation to an element. i only specify one keyframe (100%) for a simple transform. while the animation is running i pause using the animation playstate and apply a class specifying a different keyframe animation. what i want is that the second animation starts where the first animation was interrupted but instead the element jumps back to its start position and is animated from there. i played a bit with animation-fill-mode but it doesnt change which i think is because the animation was interrupted before it reached 100%. any ideas what i could do to make this work?
Upvotes: 0
Views: 725
Reputation: 972
You have a few options here:
getComputedStyle
and apply it yourself. The disadvantage of this is that for transform
, the value returned by getComputedStyle
is converted to a matrix()
value so the interpolation for rotate animations will sometimes behave differently.commitStyles()
to do it for you. The trouble with this is browser support. It should work in the latest Firefox and Safari, and next version of Chrome (works for me in Canary).You can see each approach demonstrated here: https://jsfiddle.net/birtles/8bv5of6n/14/
Upvotes: 0
Reputation: 1766
Animations don't actually change the css, they just animate it and then put it back where it was. You just have to use javascript to save the css using something like
var prevWidth = $("div").css("width");
and then after pausing the animation, set it with
$("div").css("width",prevWidth);
.
That way it stays permanently set where the first animation put it.
Upvotes: 0
Reputation: 4794
I was actually brainstorming this a couple of days ago. You are correct in assuming that your issue is the result of your animation not reaching 100%. The problem is that there is no way to simply select the values indicating how far your animation made it in the animation. From this, you have the following three options (note: I have not tested all of them):
setInterval
, etc. - Yuck!)keyframe
accordinglyUpvotes: 0