Animation.commitStyles()

The commitStyles() method of the Web Animations API's Animation interface commits the end styling state of an animation to the element being animated, even after that animation has been removed. It will cause the end styling state to be written to the element being animated, in the form of properties inside a style attribute.

Syntax

commitStyles()

Parameters

None.

Return value

None (undefined).

Examples

const divElem = document.querySelector("div");

document.body.addEventListener("mousemove", (evt) => {
  const anim = divElem.animate(
    { transform: `translate(${evt.clientX}px, ${evt.clientY}px)` },
    { duration: 500, fill: "forwards" }
  );

  anim.commitStyles();
});

Specifications

Specification
Unknown specification
# dom-animation-commitstyles

Browser compatibility

BCD tables only load in the browser

See also