Re: [csswg-drafts] [web-animations] how to make animate() method work with CSSKeyframesRule object? (#10570)

I think you should use [`element.getAnimations()`](https://drafts.csswg.org/web-animations-1/#ref-for-dom-animatable-getanimations):

```js
const box = document.querySelector("#target");

function playAnimation({ effect }) {
  const keyframes = effect.getKeyframes();
  const options = { 
    duration: 2000, 
    iterations: Infinity,
  };
  effect = new KeyframeEffect(box, keyframes, options);
  const animation = new Animation(effect);
  animation.play();
}

document.getAnimations().forEach(playAnimation);
```

-- 
GitHub Notification of comment by cdoublev
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/10570#issuecomment-2226834361 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Saturday, 13 July 2024 09:19:58 UTC