Given a web animation, such as the one over here: https://codepen.io/arxpoetica/pen/aXqEwe
How do I get CSS or style information based on state between keyframes at any given point and time?
Sample code:
<div class="thing"></div>
<style>
html {
height: 100%;
}
body {
display: flex;
justify-content: center;
align-items: center;
height: 100%;
background-color: #0a2933;
}
.thing {
height: 100px;
width: 100px;
background-color: orange;
}
</style>
<script>
document.querySelector('.thing').animate([
{ transform: 'rotate(0) scale(1)', backgroundColor: 'orange' },
{ transform: 'rotate(180deg) scale(3)', backgroundColor: 'blue' },
{ transform: 'rotate(360deg) scale(1)', backgroundColor: 'orange' }
], {
duration: 3000,
iterations: Infinity
})
</script>
NOTE: this API only works in limited browsers / platforms.
WAAPI method
.animate
returnsAnimation
object which includes all you need:Run the snippet below:
Also, WAAPI has a nice polyfill.
Hope it helps.