Skip to content

Instantly share code, notes, and snippets.

@LeaVerou
Last active June 18, 2016 12:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save LeaVerou/dda915b008971eb6808b to your computer and use it in GitHub Desktop.
Save LeaVerou/dda915b008971eb6808b to your computer and use it in GitHub Desktop.
Static interpolation via paused animations
/**
* Static interpolation via paused animations
* This technique becomes more useful if you need to interpolate more than 1 properties, and/or if you need multiple values in the spectrum
* Currently works in every modern browser except Safari
*/
@keyframes foo {
from { background: red }
to { background: yellowgreen }
}
div {
display: inline-block;
width: 100px; height: 100px;
animation: foo 1s both linear;
animation-play-state: paused;
}
div:nth-of-type(2) { animation-delay: -.2s; }
div:nth-of-type(3) { animation-delay: -.4s; }
div:nth-of-type(4) { animation-delay: -.6s; }
div:nth-of-type(5) { animation-delay: -.8s; }
div:nth-of-type(6) { animation-delay: -1s; }
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
// alert('Hello world!');
{"view":"split","fontsize":"100","seethrough":"","prefixfree":"1","page":"css"}
@marionebl
Copy link

marionebl commented Jun 18, 2016

This won't actually work in Safari, IE or Edge in any version.

Negative animation-delay is handled by the specification – if animation-delay is to be applied for animations with animation-play-state: paused; is not, so I would not bet on Safari or Edge changing their interpretation anytime soon.

You can do this WebAnimations, so I wrote a library to give you this technique in a cross-browser compatible way: https://github.com/marionebl/jogwheel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment