-
Notifications
You must be signed in to change notification settings - Fork 661
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[web-animations] how to make animate() method work with CSSKeyframesRule object? #10570
Comments
I think you should use const box = document.querySelector(".box");
function playAnimation({ effect, id }) {
if (id !== 'colorChange') return
const keyframes = effect.getKeyframes();
const options = {
duration: 2000,
iterations: 1,
};
effect = new KeyframeEffect(box, keyframes, options);
const animation = new Animation(effect);
animation.play();
}
box.getAnimations().forEach(playAnimation); |
Not really possible, you won't get the animations from that element if they're not already applied, and the request here is for a way to apply an effect on an element that has no animations applied to it. I don't think there's any way now to refer to a keyframes rule by it's name from Web Animations, and I think it would be nice to be able to do so. E.g. be able to play effects ad-hoc from a library that's already prerenderred to the document's style. I can think of two APIs that could help here:
|
The My issue is that Web Animation APIs work with POJO inputs and current CSS API returns objects like CSSKeyframesRule. Objects returned by CSS APIs are not compatible with Web Animation APIs. What I am asking is that
👍 This would be the best thing as it would save us from retrieving and converting the keyframes.
This is nice to have, but the returned objects need to be compatible with the Web Animations API. |
Well, naturally. I think this method is a common pattern when working with an animation library and it would be nice for the platform to allow that pattern. |
Related to spec https://drafts.csswg.org/web-animations-1/#dom-animatable-animate
I have key frames defined in already existing CSS:
I want to use the keyframes in JS to animate on a div:
The text was updated successfully, but these errors were encountered: