-
Notifications
You must be signed in to change notification settings - Fork 689
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[web-animations-2] Specify Animation progress API #9937
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -969,6 +969,34 @@ Add the following sentence: | |
|
||
</div> | ||
|
||
### Calculating the progress of an animation ### {#the-progress-of-an-animation} | ||
|
||
An animation's <dfn export for=animation>progress</dfn> is the ratio of its | ||
[=animation/current time=] to its [=associated effect end=]. | ||
|
||
<div algorithm="calculate animation progress"> | ||
The [=animation/progress=] of an [=animation=], |animation|, is calculated as follows: | ||
|
||
<dl class=switch> | ||
|
||
: If <em>any</em> of the following are true: | ||
* |animation| does not have an [=animation/associated effect=], or | ||
* |animation|'s [=associated effect end=] is zero, or | ||
* |animation|'s [=animation/current time=] is an [=unresolved=] time value, | ||
:: | ||
|animation|'s [=animation/progress=] is null. | ||
: If |animation|'s [=associated effect end=] is infinite, | ||
|animation|'s [=animation/progress=] is zero. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can the author tell if we're active (after the start time) or inactive (before the start time)? |
||
: Otherwise, | ||
:: | ||
<blockquote> | ||
<code><a for="animation">progress</a> = [=animation/current time=] / |animation|'s [=associated effect end=] | ||
</code> | ||
</blockquote> | ||
|
||
</dl> | ||
</div> | ||
|
||
|
||
<h3 id="animation-effects">Animation effects</h3> | ||
|
||
|
@@ -2390,7 +2418,7 @@ Update the attribute type for currentTime. | |
<h3 id="the-animation-interface">The <code>Animation</code> interface</h3> | ||
|
||
Update the startTime and currentTime of the Animation interface, and add | ||
rangeStart and rangeEnd as follows: | ||
rangeStart, rangeEnd, and progress as follows: | ||
|
||
<pre class="idl"> | ||
[Exposed=Window] | ||
|
@@ -2399,6 +2427,7 @@ partial interface Animation { | |
attribute CSSNumberish? currentTime; | ||
attribute (TimelineRangeOffset or CSSNumericValue or CSSKeywordValue or DOMString) rangeStart; | ||
attribute (TimelineRangeOffset or CSSNumericValue or CSSKeywordValue or DOMString) rangeEnd; | ||
readonly attribute double? progress; | ||
}; | ||
</pre> | ||
|
||
|
@@ -2443,6 +2472,10 @@ Add: | |
> <a href="#dom-keyframeanimationoptions-rangeend">rangeEnd</a>. | ||
> When reading the attribute, the returned value is either a | ||
> {{TimelineRangeOffset}} or the {{DOMString}} "normal". | ||
> | ||
> : <dfn attribute for=Animation>progress</dfn> | ||
> :: Specifies the [=animation/progress=] of the <a>animation</a> as a proportion of its | ||
> [=associated effect end=]. | ||
</div> | ||
|
||
<h3 id="the-animationeffect-interface">The <code>AnimationEffect</code> interface</h3> | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for making these edits. Two follow-up questions that occurred to me:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, it more accurately reflects the animated progress to return a value here.
It seems like it's more useful to allow progresses outside of the [0, 1] range, as especially for 0 it matters to know whether the effect is active or not. That said, allowing values outside of [0, 1] makes it more complicated for how to handle the 0 duration case. Perhaps we should use +/- infinity depending on whether you're before or after the start time?
@bramus @fantasai any thoughts here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking further on this, it may be simpler to restrict to [0, 1] and encourage authors to combine with the phase of the animation which seems like another thing that's not too easy to get today. Restricting to the [0, 1] range makes the answer to edge cases much easier to reason about, e.g. what we should do for a 0 duration effect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think you're right. Ultimately, though, it probably depends on how we expect the API to be used.
We could mimic the behaviour of
progress
onComputedEffectTiming
and use the fill mode and phase of the root animation effect to makeprogress
beunresolved
when the root effect is not in effect but that might be a bit of a layering violation?For reference, I believe
ComputedEffectTiming.progress
is mostly in the range [0, 1] but can extend outside that range due to easing functions.I guess it comes back to reviewing these issues and seeing what would work best in each of those cases (quoting #8799):