-
Notifications
You must be signed in to change notification settings - Fork 748
Open
Labels
web-animations-2Current WorkCurrent Work
Description
Problem
- If you manually construct an
Animation
to be played at a later time, there's no way to know when it's actually playing. - If the animation has a
delay
, there's no way to know when the animation effect actually starts.
let animation = new Animation(new KeyframeEffect(element, { opacity: 1 }, { delay: 1000, duration: 2000 }));
animation.ready.then(_ => {
console.log("animation is ready"); // this is logged immediately
});
window.setTimeout(_ => {
animation.play()
}, 1500);
// When will animation play?
// When will the delay period end?
Proposal
Introduce two new promises on Animation
:
Animation.playing
: returns aPromise
which resolves once the animation has started playing.Animation.started
: returns aPromise
which resolves once thedelay
period is over and the effect has started
let animation = new Animation(new KeyframeEffect(element, { opacity: 1 }, { delay: 1000, duration: 2000 }));
animation.ready.then(_ => {
console.log("animation is ready"); // @ time = 0
});
animation.playing.then(_ => {
console.log("animation is playing"); // @ time = 1500
});
animation.started.then(_ => {
console.log("animation effect started"); // @ time = 2500
});
animation.finished.then(_ => {
console.log("animation effect started"); // @ time = 4500
});
window.setTimeout(_ => {
animation.play()
}, 1500);
Alternatives
Animation.played
instead ofAnimation.playing
for consistency in tense withAnimation.finished
Animation.effectStarted
instead ofAnimation.started
for clarification
Metadata
Metadata
Assignees
Labels
web-animations-2Current WorkCurrent Work