marionebl
marionebl

Reputation: 3382

Control keyframe animation progress via static interpolation

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:

Problem

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?

Technique

Examples

Upvotes: 2

Views: 1345

Answers (1)

marionebl
marionebl

Reputation: 3382

The problem

The solution

To 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:

  • Get computed animation-name for a given HTMLElement
  • Search document.styleSheets for matching CSSKeyFramesRules
  • Transform the found CSSKeyFrameRule to an array of keyframes compatible with the upcoming element.animate, which is part of the proposed WebAnimations standard
  • Provide an API that allows for control of the animation in relation to its timeline length

To 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

Related Questions