Reputation: 3382
Given you want to control the progress of a CSS keyframe animation by manipulating the animation-delay
property while animation-play-state
is set to paused.
This should:
For reasons motivated by render performance and proper separation of concerns you want it not to:
The animation-delay
technique appears not to work with the following browsers (problems can be reproduced in both provided examples)
Is there any way to produce the desired behavior for all browsers while fulfilling all requirements outlined above?
Upvotes: 2
Views: 1345
Reputation: 3382
animation-play-state
in combination with animation-delay
unambiguously enough to call out IE and Safari for their deviating implementations. See http://www.w3.org/TR/css3-animations/#animation-delay and http://www.w3.org/TR/css3-animations/#animation-play-stateTo partially cover the requirements outlined above I implemented a library called jogwheel that allows for timeline control of animations declared via CSS keyframe animations. To achieve this jogwheel does the following:
animation-name
for a given HTMLElement
document.styleSheets
for matching CSSKeyFramesRule
sCSSKeyFrameRule
to an array of keyframes compatible with the upcoming element.animate
, which is part of the proposed WebAnimations standardTo use jogwheel you'll have to
Install the library:
npm install --save jogwheel web-animations-js
In your JavaScript:
// WebAnimations polyfill required
require('web-animations');
var JogWheel = require('jogwheel');
var element = document.querySelector('[data-animated]');
var wheel = JogWheel.create(element);
// Jumps midway into animation
wheel.seek(0.5);
Upvotes: 3