Skip to content

Commit

Permalink
[web-animations-2] Specify Animation progress API (#9937)
Browse files Browse the repository at this point in the history
Define animation progress calculation, where:
* infinite duration results in 0 progress
* progress is clamped to [0,1] if before the start or after the end time.
  • Loading branch information
DavMila authored Feb 29, 2024
1 parent 145b355 commit 79819a4
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion web-animations-2/Overview.bs
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,41 @@ 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 [=animation/current time=] is an [=unresolved=] time value,
::
|animation|'s [=animation/progress=] is null.
: If |animation|'s [=associated effect end=] is zero,
::
: If |animation|'s [=animation/current time=] is negative,
:: |animation|'s [=animation/progress=] is zero.

: Otherwise,
:: |animation|'s [=animation/progress=] is one.
: If |animation|'s [=associated effect end=] is infinite,
::
|animation|'s [=animation/progress=] is zero.
: Otherwise,
::
<blockquote>
<code><a for="animation">progress</a> = min(max([=animation/current time=] / |animation|'s [=associated effect end=], 0), 1)
</code>
</blockquote>

</dl>
</div>


<h3 id="animation-effects">Animation effects</h3>

Expand Down Expand Up @@ -2390,7 +2425,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]
Expand All @@ -2399,6 +2434,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>

Expand Down Expand Up @@ -2443,6 +2479,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>
Expand Down

0 comments on commit 79819a4

Please sign in to comment.