Repository navigation
[web-animations-2] Progress APIs #8799
Description
In #8669, #8765 and #8201 there seems to be a common desire to have more convenient APIs for getting some representation of progress. Currently you can get the progress of the current iteration of an effect using the getComputedTiming() API as follows:
let progress = animation.effect.getComputedTiming().progress;You can also get the overall effect progress by doing a calculation such as:
let progress = animation.currentTime / animation.effect.getComputedTiming().endTime;However, with several of the other linked issues it seems that it would be convenient for developers to have some form of access to the progress through the attached animation range, or to get that progress directly from the timeline.
We could add a convenience currentProgress helper alongside the currentTime API on Animation:
attribute double? currentProgress;
This could return the progress of currentTime through the entire range before which it is considered complete, e.g. calculated as follows:
currentProgress = currentTime / effect endTime
Note that endTime is infinite when either iterations or duration is infinite. In these cases currentProgress should probably be null or undefined?
Open question - should it be read only or should we allow setting the progress which would be equivalent to setting currentTime to currentProgress * endTime?
As per discussion on #8669 a progress reported on animation should be mostly independent of the effect timing, so we calculate it as the progress from startTime to the time when the animation would resolve its finished promise. This would intentionally not match the progress through the developer specified keyframes.
I also propose that given the uncertainty around what's expected from the getCurrentTime API on timeline, that we remove it until we have a better understanding of the specific use cases that developers need it for. Perhaps the animation progress API above will address some of them where it seems developers were trying to work this out through the timeline.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsRegular agenda items
Activity
birtles commentedon May 6, 2023
Overall it seems reasonable to me. I think defining it in terms of
startTimeandendTimeis a nice way of keeping it at arms length from effect timing.Mathematically, should it be zero? Not sure if that would be the most useful result, however.
I'd suggest making it readonly. As you pointed out, there are some cases where this value would be
null/undefined/0or somesuch, and in those cases if set made it writeable I guess the setter would throw?We already have enough ways of changing the animation position (setting
currentTime, settingstartTime, calling the various playback methods etc.) and it's easy enough to make a read-only attribute writeable later if compelling use cases present themselves.flackr commentedon May 10, 2023
Yeah, mathematically it would be 0. I don't have a strong preference for it to be null/undefined, just thought it might be marginally more meaningful than 0 to distinguish from the case of a 0 that can make progress.
bramus commentedon May 12, 2023
In favor of this general approach as described here, to tackle #8669.
Fine with making it readonly as a starting point.
flackr commentedon May 12, 2023
Thanks @bramus. Adding to agenda to discuss/resolve:
ydaniv commentedon May 13, 2023
Regarding 1. +1 on adding, with 2 suggestions:
currentTimebehavior and allow setting progress through this endpoint. It will both be, IMHO, more handy for authors, and if I'm not mistaken, should be necessary for animations withduration: auto.progress?css-meeting-bot commentedon May 24, 2023
The CSS Working Group just discussed
[web-animations-2] Progress APIs, and agreed to the following:RESOLVED: Add progress to Animation and make it readonlyThe full IRC log of that discussion
<faceless> present-<bramus> flackr: So WAAPI is very focused on absolute times, but with scroll-driven aninamations, developers often just work with progress instead of time
<bramus> flackr: seems like a reasonable thing to add, so there is a proposal to get the current progress which is a calcuation between start and and end time
<bramus> flackr: also need to specify what hsould happen for infinitely repeating animations
<bramus> flackr: Proposal is adding currentProgress to Animation
<bramus> flackr: it is calculated as currentTime / effect endTime
<bramus> flackr: propose to make it readonly for now
<bramus> s/repeating/duration/
<bramus> Rossen_: Any feedback?
<ydaniv> I proposed "progress" instead of "currentProgress"
<TabAtkins> +1
<TabAtkins> (to the current proposal, no opinion on naming)
<bramus> Rossen_: You are taking into account the feedback from ydaniv?
<bramus> flackr: Yes, he proposed currentProgress instead of progress
<bramus> flackr: dont object to this shorter name and computedTIming value from the effect is also called progress
<bramus> Rossen_: what about read/write vs readonly?
<bramus> flackr: then have to decide how to handle infinite duration animation
<bramus> Rossen_: starting with readonly gives up path to go forward later
<bramus> Rossen_: Should we formulate as readonly? not hearing objections from yehonathan
<bramus> flackr: would be happy with that
<bramus> bramus: me too
<bramus> Rossen_: objections to adding as readonly?
<bramus> Rossen_: Not hearing anything
<bramus> bramus: and the name?
<bramus> flackr: we said progress
<bramus> flackr: Proposed resolution: add progress to Animation and make it readonly
<bramus> RESOLVED: Add progress to Animation and make it readonly
flackr commentedon Feb 29, 2024
On the PR from @DavMila there is one point where we don't have a clear answer. Should the progress be clamped to [0, 1]. For the full discussion you can view the PR review #9937 (comment) however I'll do my best to summarize the pros and cons of each.
fill = backwards | both). However, this also means that to correctly reflect the progress for 0 duration animations we would likely have to return-InfinityandInfinitywhen you are before or at/after the start time respectively.Ultimately, I think either works, but which is better comes back to how authors will use this. @bramus @fantasai @birtles any thoughts?
ydaniv commentedon Feb 29, 2024
I'm leaning towards 2, since this will probably be used to sync a scroll/view timeline with another effect that can't be done with CSS, e.g.: canvas, SVG, video.
So, I think that as default behavior, having this perform as a sort of "manual" CustomEffect, with a clamped progress like KeyframeEffect's is a good way to start, and we could add a new property in the future, like you said, to reflect the more complex cases.
birtles commentedon Feb 29, 2024
I agree that 2 makes most sense. I also think, as per the current PR, we shouldn't try to reflect the fill mode of the associated effect.
ydaniv commentedon Mar 1, 2024
However, if we consider the above use-cases, having enter/exit events on the animations, similar requested by @bramus on #7962 may become quite crucial for easily creating such effects without extra IntersectionObserver or
scrollhandler.Although you can currently get a similar outcome with
start/endevents on CSS Animations like here: https://jsbin.com/jizahopixe/edit?css,js,console,outputI think it's currently not possible to achieve with WAAPI.
17 remaining items
[web-animations-2] Change progress to overallProgress
yisibl commentedon Nov 13, 2024
Can we add these APIs to CSS?
ydaniv commentedon Nov 13, 2024
Do you mean to the
CSSAnimationinterface? It inherits fromAnimation, so naturally yes.[web-animations-2] Change progress to overallProgress (#11184)
graouts commentedon Nov 25, 2024
I'm making the required WPT change also in web-platform-tests/wpt#49353.
Rename Animation.progress to Animation.overallProgress
Rename Animation.progress to Animation.overallProgress
Rename Animation.progress to Animation.overallProgress
Bug 1933609 [wpt PR 49385] - Rename Animation.progress to Animation.o…
Bug 1933609 [wpt PR 49385] - Rename Animation.progress to Animation.o…
Bug 1933609 [wpt PR 49385] - Rename Animation.progress to Animation.o…
Bug 1933609 [wpt PR 49385] - Rename Animation.progress to Animation.o…
ydaniv commentedon Jan 26, 2025
@flackr @DavMila can we close this one?
DavMila commentedon Jan 27, 2025
Yes we can. I don't believe there's any outstanding issue.