Animation.finish()

This is an experimental technology
Because this technology's specification has not stabilized, check the compatibility table for usage in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future versions of browsers as the specification changes.

The Animation.finish() method of the Animation Interface seeks to either end of an animation, depending on whether the animation is playing or reversing.

Syntax

JavaScript
animation.finish(); 

Parameters

None.

Return Value

None.

Exceptions

An InvalidState error is raised if the player's playback rate is 0 or the animation's playback rate is greater than 0 and the end time of the animation is infinity.

Examples

The following example shows how to use the finish() method and catch an InvalidState error.

JavaScript
interfaceElement.addEventListener("mousedown", function() {
  try {
    player.finish();
  } catch(e if e instanceof InvalidState) {
    console.log("finish() called on paused or finished animation.");
  } catch(e);
    logMyErrors(e); //pass exception object to error handler
  }
});

The following example finishes all the animations on a single element, regardless of their direction of playback.

JavaScript
elem.getAnimations().forEach(
  function(animation){ 
    return animation.finish();
  }
);

Specifications

Specification Status Comment
Web Animations
The definition of 'finish()' in that specification.
Working Draft  

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 39.0 48 (48) No support No support No support
Feature Android Android Webview Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile Chrome for Android
Basic support No support 39.0 48.0 (48) No support No support No support 39.0

 

See also

License

© 2016 Mozilla Contributors
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-us/docs/web/api/animation/finish

Animation API Experimental Interface Method Reference waapi web animations api