Skip to content

Commit 0e0969b

Browse files
committed
[web-animations-1] Make commitStyles use an endpoint-inclusive active interval
Fixes #5394.
1 parent 734be21 commit 0e0969b

File tree

1 file changed

+46
-23
lines changed

1 file changed

+46
-23
lines changed

web-animations-1/Overview.bs

+46-23
Original file line numberDiff line numberDiff line change
@@ -2801,6 +2801,11 @@ Animation effects {#animation-effects}
28012801
<code>max(min(<a>start delay</a> + <a>active duration</a>,
28022802
<a for="animation effect">end time</a>), 0)</code>
28032803

2804+
2805+
Furthermore, an <dfn>endpoint-inclusive active interval</dfn> flag
2806+
may be specified when determining the phase.
2807+
If not specified, it is assumed to be false.
2808+
28042809
An [=animation effect=] is in the
28052810
<dfn export for="animation effect">before phase</dfn>
28062811
if the animation effect's [=local time=]
@@ -2809,7 +2814,8 @@ Animation effects {#animation-effects}
28092814

28102815
* the [=local time=] is less than the [=before-active boundary time=],
28112816
<em>or</em>
2812-
* the [=animation direction=] is “backwards”
2817+
* the [=animation direction=] is “backwards”,
2818+
the [=endpoint-inclusive active interval=] flag is false,
28132819
and the [=local time=] is equal to the [=before-active boundary time=].
28142820

28152821
An [=animation effect=] is in the
@@ -2820,7 +2826,8 @@ Animation effects {#animation-effects}
28202826

28212827
* the [=local time=] is greater than the [=active-after boundary time=],
28222828
<em>or</em>
2823-
* the [=animation direction=] is “forwards”
2829+
* the [=animation direction=] is “forwards”,
2830+
the [=endpoint-inclusive active interval=] flag is false,
28242831
and the [=local time=] is equal to the [=active-after boundary time=].
28252832

28262833
An [=animation effect=] is in the
@@ -3001,34 +3008,24 @@ Animation effects {#animation-effects}
30013008
</div>
30023009

30033010
<div class=example>
3004-
Alternatively, the author can set the specified style
3005-
at the start of the animation and then animate <em>from</em>
3006-
the original value as illustrated below:
3011+
More conveniently, an {{Animation}}'s {{Animation/commitStyles}} method can
3012+
be used to produce the same effect.
30073013

30083014
<pre highlight=javascript>
3009-
elem.style.transform = 'translateY(100px)';
3010-
elem.animate({ transform: 'none', offset: 0 }, 200);
3015+
elem.animate({ transform: 'translateY(100px)' }, 200).finished.then(() => {
3016+
elem.commitStyles();
3017+
});
30113018
</pre>
30123019
</div>
30133020

30143021
<div class=example>
3015-
Complex effects involving layering many animations on top of one another
3016-
could require temporary use of forwards fill modes
3017-
to capture the final value of an animation before canceling it.
3018-
For example:
3022+
Alternatively, the author can set the specified style
3023+
at the start of the animation and then animate <em>from</em>
3024+
the original value as illustrated below:
30193025

30203026
<pre highlight=javascript>
3021-
elem.addEventListener('click', async evt => {
3022-
const animation = elem.animate(
3023-
{ transform: \`translate(${evt.clientX}px, ${evt.clientY}px)\` },
3024-
{ duration: 800, fill: 'forwards' }
3025-
);
3026-
await animation.finished;
3027-
// commitStyles will record the style up to and including \`animation\` and
3028-
// update elem's specified style with the result.
3029-
animation.commitStyles();
3030-
animation.cancel();
3031-
});
3027+
elem.style.transform = 'translateY(100px)';
3028+
elem.animate({ transform: 'none', offset: 0 }, 200);
30323029
</pre>
30333030
</div>
30343031

@@ -4890,6 +4887,28 @@ The {{Animation}} interface {#the-animation-interface}
48904887
calling this method <em>does</em> trigger a [=style change event=]
48914888
(see [[#model-liveness]]).
48924889

4890+
<div class=note>
4891+
4892+
In order to simplify the common case
4893+
of persisting a completed animation,
4894+
the procedure to [=commit computed styles=]
4895+
uses endpoint-*inclusive* timing (see [[#interval-timing]])
4896+
when determining the phase of the animation
4897+
(see [[#animation-effect-phases-and-states]]).
4898+
4899+
As a result, the following code will persist
4900+
the `transform: translateY(100px)` style in specified style
4901+
despite not having a
4902+
[=fill mode=] of [=fill mode/forwards=] or [=fill mode/both=].
4903+
4904+
<pre highlight=javascript>
4905+
elem.animate({ transform: 'translateY(100px)' }, 200).finished.then(() => {
4906+
elem.commitStyles();
4907+
});
4908+
</pre>
4909+
4910+
</div>
4911+
48934912
<div class=note>
48944913

48954914
Since the procedure to [=commit computed styles=]
@@ -4986,7 +5005,11 @@ The {{Animation}} interface {#the-animation-interface}
49865005
1. Let |effect value| be the result of calculating
49875006
the result of |partialEffectStack| for |property|
49885007
using |target|'s computed style
4989-
(see [[#calculating-the-result-of-an-effect-stack]]).
5008+
(see [[#calculating-the-result-of-an-effect-stack]]) and
5009+
setting the [=endpoint-inclusive active interval=] flag
5010+
to true
5011+
when calculating the animation effect phase
5012+
(see [[#animation-effect-phases-and-states]]).
49905013

49915014
1. [=Set a CSS declaration=] of |property| for |effect value|
49925015
in |inline style|.

0 commit comments

Comments
 (0)