This is an experimental technology
Because this technology's specification has not stabilized, check the compatibility table for the proper prefixes to use 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 spec changes.
The reverse()
method of the Animation
Interface moves the animation backwards, stopping at the start of the animation. If called on an unplayed animation, the whole animation is played backwards. If called on a paused animation, the animation will continue in reverse.
SyntaxEdit
element.reverse();
ExampleEdit
The following example uses reverse()
to toggle from an "after" image to a "before" image. This would be paired with similar code to do the opposite using play()
.
beforeButton = document.getElementById("before");
beforeButton.addEventListener('mousedown', function() {
player.reverse();
});
SpecificationsEdit
Specification | Status | Comment |
---|---|---|
Web Animations The definition of 'reverse()' in that specification. |
Working Draft |
Browser compatibilityEdit
[1] Before Firefox 40, this property was implemented on the AnimationPlayer
interface.
See alsoEdit
AnimationPlayer
for other methods and properties you can use to control web page animation.AnimationPlayer.pause()
to pause an animation.AnimationPlayer.play()
to move an animation forward.