diff --git a/packages/animations/browser/src/render/web_animations/web_animations_player.ts b/packages/animations/browser/src/render/web_animations/web_animations_player.ts index 15df9eef13..b0b0caa661 100644 --- a/packages/animations/browser/src/render/web_animations/web_animations_player.ts +++ b/packages/animations/browser/src/render/web_animations/web_animations_player.ts @@ -156,6 +156,9 @@ export class WebAnimationsPlayer implements AnimationPlayer { } setPosition(p: number): void { + if (this.domPlayer === undefined) { + this.init(); + } this.domPlayer.currentTime = p * this.time; } diff --git a/packages/animations/browser/test/render/web_animations/web_animations_player_spec.ts b/packages/animations/browser/test/render/web_animations/web_animations_player_spec.ts index 8c8155aafd..b5543dd5fe 100644 --- a/packages/animations/browser/test/render/web_animations/web_animations_player_spec.ts +++ b/packages/animations/browser/test/render/web_animations/web_animations_player_spec.ts @@ -67,6 +67,27 @@ import {WebAnimationsPlayer} from '../../../src/render/web_animations/web_animat player.finish(); expect(log).toEqual(['started', 'done']); }); + + it('should allow setting position before animation is started', () => { + const player = new WebAnimationsPlayer(element, [], {duration: 1000}); + + player.setPosition(0.5); + const p = innerPlayer!; + expect(p.log).toEqual(['pause']); + expect(p.currentTime).toEqual(500); + }); + + it('should continue playing animations from setPosition', () => { + const player = new WebAnimationsPlayer(element, [], {duration: 1000}); + + player.play(); + const p = innerPlayer!; + expect(p.log).toEqual(['play']); + + player.setPosition(0.5); + expect(p.currentTime).toEqual(500); + expect(p.log).toEqual(['play']); + }); }); }