// Start the animation
const animation = animatedElement.animate(
{ transform: "translate(100px)" },
{ duration: 500, fill: "forwards" },
);
// Wait for the animation to finish
await animation.finished;
// Commit animation state to he animatedElement style attribute
animation.commitStyles();
// Cancel the animation
animation.cancel();Animation: commitStyles() method / notebook
Animation: commitStyles() method
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
// Start the animation
const animation = animatedElement.animate(
{ transform: "translate(100px)" },
{ duration: 500 },
);
// Wait for the animation to finish
await animation.finished;
// Commit animation state to the animatedElement style attribute
animation.commitStyles();<button class="commit-styles">commitStyles() only</button>
<button class="commit-with-fill">commitStyles() with fill</button>
<button class="no-commit-or-fill">No commitStyles() or fill</button>