web-animations / web-animations-js-legacy

The original emulator of the Web Animations specification. Please use web-animations-js instead:
https://github.com/web-animations/web-animations-js
Apache License 2.0
707 stars 84 forks source link

Reversing on currentTime 0 performs a full reverse animation. #610

Closed kitsunde closed 10 years ago

kitsunde commented 10 years ago

Given:

var animation = new Animation(el,
    [
        {transform: "translate(0,0)"},
        {transform: "translate(0,100%)"}
    ], {duration: 2000});

var player = document.timeline.play(animation);
player.reverse();
player.play();

It will animate as if player.currentTime was 2000 initially. Which seems to be different from the spec (3.5.2.3 Limiting the current time):

When the player playback rate is negative, the current time does not progress past time zero although it may be seeked to a negative time.

It should probably just finish the player. Strangely if I just do reverse() without the 2nd play() nothing happens. The second play() shouldn't behave this way though since the player can be paused at 0 through this pattern:

var player = document.timeline.play(animation);
player.pause();
player.reverse();
player.play();

Concrete JSFiddle: http://jsfiddle.net/kitsunde/WmH35/2/

alancutter commented 10 years ago

This is intended behaviour, see the play method for AnimationPlayers: http://dev.w3.org/fxtf/web-animations/#methods-1

Calling play() will restart finished players by seeking to the "beginning" of their source animation relative to the player's playback rate. This is similar to pressing play on a typical video player after the video has finished.

kitsunde commented 10 years ago

@alancutter It seems like reverse() on time 0 causes the player to be finished (even when paused), is the root of my confusion. Thanks for the explanation.