For the animation library I'm making, I want transitions and animations.
Transitions were simple. I can easily access the transition property from the style property of an element object:
document.body.style['-webkit-transition'] = "background 1s";
document.body.background = "#f00";
I know that in CSS, there are 2 parts to animations, @-keyframes and then calling the actual animation.
How do I assign an @-keyframe rule through pure JavaScript?
It wouldn't be something like transitions, because @-keyframe rules aren't applied directly to elements.
An alternative to this would be to dynamically create an @-keyframes rule through JavaScript from a string, and append it to a temporary stylesheet. Kind of sloppy, which is why I'm wondering how to do it directly through the DOM.
Is there a way? From what I have seen on some other sites, you can play animations and stop them at certain keyframes, but how do you create the animations themselves?