-
Notifications
You must be signed in to change notification settings - Fork 797
[animation-triggers-1] Update AnimationTrigger specification #14044
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
Open
DavMila
wants to merge
3
commits into
w3c:main
Choose a base branch
from
DavMila:timeline-trigger
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all 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 hidden or 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 |
|---|---|---|
|
|
@@ -26,6 +26,10 @@ Markup Shorthands: markdown yes | |
| <pre class=link-defaults> | ||
| spec:infra; type:dfn; text:user agent | ||
| spec:dom; type:dfn; for:/; text:shadow root | ||
| spec:web-animations-1; type:dfn; | ||
| text:pause an animation | ||
| text:animation effect | ||
| text:fill mode | ||
| </pre> | ||
|
|
||
| <pre class=anchors> | ||
|
|
@@ -106,7 +110,126 @@ urlPrefix: https://www.w3.org/TR/web-animations-1/; type: dfn | |
| █▌ █▌ █▌ ████ ███▌ ███▌ █████▌ █▌ █▌ ███▌ | ||
| --> | ||
|
|
||
| # Triggers # {#triggers} | ||
| # Animation Triggers # {#triggers} | ||
| ----------------- | ||
|
|
||
| ## Overview ## {#triggers-overview} | ||
|
|
||
| An <dfn export>animation trigger</dfn> can be used to control the playback | ||
| of [=animations=] associated with the trigger. | ||
|
|
||
| Each [=animation trigger=] maintains the following fields internally: | ||
|
|
||
| 1. an <dfn lt="animation trigger active" export>active</dfn> flag, which is initially false, | ||
|
|
||
| 1. a <dfn lt="animation trigger invokes deactivation" export>invokes deactivation</dfn> flag, | ||
| which is initially false, and, | ||
|
|
||
| 1. a set of [=animations=], <dfn lt="animation trigger animation set" export>animations set</dfn>, | ||
| which is initially empty. | ||
|
|
||
| Each [=animation trigger=] associates each [=animation=] in its | ||
| [=animation trigger animation set|animations set=] with two <<animation-action>>s. One action is | ||
| associated with [=invoke activation|activation=] and the other is associated with | ||
| [=invoke deactivation|deactivation=]. | ||
|
|
||
| ## Invoking Activation & Deactivation ## {#animation-trigger-activation-deactivation} | ||
|
|
||
| When asked to <dfn lt="invoke activation">invoke activation</dfn> given a [=trigger=] <var>trigger</var>, | ||
|
Contributor
Author
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. FYI @tabatkins: I realize we'd rather not have algorithms in spec but I figured these algorithms are short and not overly complicated... so perhaps they make are still a good way to spec the attributes/behavior common to different trigger types. |
||
| the user agent should perfrom the following steps: | ||
|
|
||
| 1. If |trigger|'s [=animation trigger active|active=] flag is true, abort these steps. | ||
|
|
||
| 1. Set |trigger|'s [=animation trigger active|active=] flag to true. | ||
|
|
||
| 1. For each [=animation=] <var>animation</var> in |trigger|'s [=animation trigger animation set|animations set=], | ||
| 1. Run the steps to <a>perform activation</a> with |trigger| as trigger and |animation| as animation. | ||
|
|
||
| 1. If |trigger|'s [=animation trigger invokes deactivation|invokes deactivation=] flag is false, | ||
| set |trigger|'s [=animation trigger active|active=] flag to false. | ||
|
|
||
| When asked to <dfn perform activation on an animation export>perform activation</dfn> given a | ||
| [=animation trigger|trigger=] <var>trigger</var> and an [=animation=] <var>animation</var>, the user | ||
| agent should perform these steps: | ||
|
|
||
| 1. Let <var>action</var> be the <<animation-action>> which |trigger| associates with | ||
| [=invoke activation|activation=] for |animation|. | ||
|
|
||
| 1. Perform the steps corresponding to |action| in the <<animation-action>> table on |animation|. | ||
|
|
||
| When asked to <dfn lt="invoke deactivation">invoke deactivation</dfn> given a [=trigger=] <var>trigger</var>, | ||
| the user agent should perfrom the following steps: | ||
|
|
||
| 1. If |trigger|'s [=animation trigger active|active=] flag is false, abort these steps. | ||
|
|
||
| 1. Set |trigger|'s [=animation trigger active|active=] flag to false. | ||
|
|
||
| 1. For each [=animation=] <var>animation</var> in |trigger|'s [=animation trigger animation set|animations set=], | ||
| 1. Run the steps to <a>perform deactivation</a> with |trigger| as trigger and |animation| as animation. | ||
|
|
||
| When asked to <dfn perform deactivation on an animation export>perform deactivation</dfn> given a | ||
| [=animation trigger|trigger=] <var>trigger</var> and an [=animation=] <var>animation</var>, the user | ||
| agent should perform these steps: | ||
|
|
||
| 1. Let <var>action</var> be the <<animation-action>> which |trigger| associates with | ||
| [=invoke deactivation|deactivation=] for |animation|. | ||
|
|
||
| 1. Perform the steps corresponding to |action| in the <<animation-action>> table on |animation|. | ||
|
|
||
| Issue: Should there be any effect of triggers on scroll-driven animations? | ||
|
|
||
| ## Attaching an Animation to an AnimationTrigger ## {#animation-trigger-attach-animation} | ||
|
|
||
| When asked to <dfn lt="attach an animation to a trigger" export>attach an animation to a trigger</dfn> given an [=animation trigger=] | ||
| <var>trigger</var>, an [=animation=] <var>animation</var>, an {{AnimationTriggerAction}} <var>activateAction</var> | ||
| and an {{AnimationTriggerAction}} <var>deactivateAction</var>, run the following steps: | ||
|
|
||
| 1. If |animation| is currently attached to another [=animation trigger=], | ||
| <a>throw</a> a <span class=exceptionname>NotSupportedError</span>. | ||
|
|
||
| 1. If |deactivateAction| is not given, set |deactivateAction| to {{AnimationTriggerAction/none}}. | ||
|
|
||
| 1. Let <var>activationAction</var> be the <<animation-action>> that corresponds to |activateAction|. | ||
|
|
||
| 1. Let <var>deactivationAction</var> be the <<animation-action>> that corresponds to |deactivateAction|. | ||
|
|
||
| 1. If the [=animation/play state=] of |animation| is [=play state/idle=], | ||
| 1. Run the steps to [=pause an animation=] on |animation|. | ||
|
|
||
| 1. Let <var>currentActivationAction</var> be the <<animation-action>> which |trigger| associates | ||
| with [=invoke activation|activation=] for |animation| | ||
| or ''<animation-action>/none'' if |animation| was not previously in |trigger|'s | ||
| [=animation trigger animation set|animations set=]. | ||
|
|
||
| 1. Add |animation| to |trigger|'s [=animation trigger animation set|animations set=]. | ||
|
|
||
| 1. Set the <<animation-action>> which |trigger| associates with its [=invoke activation|activation=] for |animation| to |activationAction|. | ||
|
|
||
| 1. Set the <<animation-action>> which |trigger| associates with its [=invoke deactivation|deactivation=] for |animation| to |deactivationAction|. | ||
|
|
||
| 1. If |trigger|'s [=animation trigger active|active=] flag is true, | ||
|
|
||
| 1. If |currentActivationAction| is not the same as |activationAction|, | ||
| 1. Run the steps to <a>perform activation</a> with |trigger| as trigger and |animation| as animation. | ||
|
|
||
| NOTE: Attaching multiple triggers to an animation is not supported currently but will eventually be | ||
| supported. | ||
|
|
||
| NOTE: When pausing the animation in step 5, the user agent should also set a boundary-exclusive flag | ||
| on |animation| and its [=animation effect=]. However, that flag is not yet implemented. Setting the | ||
| boundary-exclusive flag allows authors control over the "pre-triggered" visual state of a triggered | ||
| animation by making its visual state depend on its [=/fill mode=]. | ||
|
|
||
| ISSUE: We react to post-activation attachment, but not post-deactivation. Perhaps we should react to | ||
| both or neither. | ||
|
|
||
| When asked to <dfn lt="detach an animation from a trigger" export>detach an animation from a trigger</dfn> | ||
| given an [=animation trigger=] <var>trigger</var>, an [=animation=] <var>animation</var>, | ||
| run the following steps: | ||
|
|
||
| 1. Remove |animation| from |trigger|'s [=animation trigger animation set|animation set=]. | ||
|
|
||
| ## Triggers Declared By CSS ## {#css-animation-triggers} | ||
|
|
||
| While CSS animations are, by default, | ||
| automatically run as soon as the appropriate 'animation' values have been set on an element, | ||
|
|
@@ -628,6 +751,109 @@ urlPrefix: https://www.w3.org/TR/web-animations-1/; type: dfn | |
| </caption> | ||
| </table> | ||
|
|
||
| <h2 id="programming-interface">Programming interface</h2> | ||
|
|
||
| <h3 id="the-animationtrigger-interface">The <code>AnimationTrigger</code> interface</h3> | ||
|
|
||
| <xmp class=idl> | ||
| [Exposed=Window] | ||
| interface AnimationTrigger { | ||
| undefined addAnimation(Animation animation, AnimationTriggerAction activateAction, optional AnimationTriggerAction deactivateAction); | ||
| undefined removeAnimation(Animation animation); | ||
| sequence<Animation> getAnimations(); | ||
| }; | ||
| </xmp> | ||
|
|
||
| <wpt> | ||
| interfaces/TimelineTrigger/constructor.html | ||
| </wpt> | ||
|
|
||
| ### The {{AnimationTriggerAction}} enumeration ### {#the-animationtriggeraction-enumeration} | ||
|
|
||
| <xmp class=idl> | ||
| enum AnimationTriggerAction { | ||
| "play", | ||
| "pause", | ||
| "reset", | ||
| "play-once", | ||
| "play-forwards", | ||
| "play-backwards", | ||
| "replay", | ||
| "none" | ||
| }; | ||
| </xmp> | ||
|
|
||
| <dl dfn-type=enum-value dfn-for="AnimationTriggerAction"> | ||
| : <dfn>play</dfn> | ||
| :: Corresponds to ''<animation-action>/play''. | ||
| : <dfn>pause</dfn> | ||
| :: Corresponds to ''<animation-action>/pause''. | ||
| : <dfn>reset</dfn> | ||
| :: Corresponds to ''<animation-action>/reset''. | ||
| : <dfn>play-once</dfn> | ||
| :: Corresponds to ''<animation-action>/play-once''. | ||
| : <dfn>play-forwards</dfn> | ||
| :: Corresponds to ''<animation-action>/play-forwards''. | ||
| : <dfn>play-backwards</dfn> | ||
| :: Corresponds to ''<animation-action>/play-backwards''. | ||
| : <dfn>replay</dfn> | ||
| :: Corresponds to ''<animation-action>/replay''. | ||
| : <dfn>none</dfn> | ||
| :: Corresponds to ''<animation-action>/none''. | ||
| </dl> | ||
|
|
||
| <div dfn-type=method class=methods | ||
| dfn-for="AnimationTrigger"> | ||
|
|
||
| : <dfn lt="addAnimation(Animation animation, AnimationTriggerAction activateAction, optional AnimationTriggerAction deactivateAction)">undefined addAnimation(|animation|, |activateAction|, |deactivateAction|)</dfn> | ||
| :: | ||
| Perform the following steps: | ||
|
|
||
| 1. Let |trigger| be the object the method was called on. | ||
|
|
||
| 2. Run the steps to [=attach an animation to a trigger=] with |trigger| as the |trigger| argument, | ||
| |animation| as the |animation| argument, |activateAction| as the |activateAction| argument, | ||
| and |deactivateAction| as the |deactivateAction| argument. | ||
|
|
||
| <div dfn-type=argument class=parameters | ||
| dfn-for="AnimationTrigger/addAnimation(animation, activateBehavior, deactivateBehavior)"> | ||
|
|
||
| : <dfn>animation</dfn> | ||
| :: | ||
| The [=animation=] to attach to the trigger. | ||
|
|
||
| : <dfn>activateAction</dfn> | ||
| :: | ||
| The {{AnimationTriggerAction}} corresponding to the <<animation-action>> which is intended for the | ||
| trigger to associate with [=invoke activation|activation=] | ||
| for {{AnimationTrigger/addAnimation(animation, activateBehavior, deactivateBehavior)/animation}}. | ||
|
|
||
| : <dfn>deactivateAction</dfn> | ||
| :: | ||
| The {{AnimationTriggerAction}} corresponding to the <<animation-action>> which is intended the trigger | ||
| to associate with [=invoke deactivation|deactivation=] | ||
| for {{AnimationTrigger/addAnimation(animation, activateBehavior, deactivateBehavior)/animation}}. | ||
|
|
||
| </div> | ||
|
|
||
| : <dfn lt="removeAnimation(animation)">undefined removeAnimation(|animation|)</dfn> | ||
| :: | ||
| 1. Let |trigger| be the object on which this method was called. | ||
|
|
||
| 1. Run the steps to [=detach an animation from a trigger=] with |trigger| as the |trigger| | ||
| argument and |animation| as the |animation| argument. | ||
|
|
||
| <div dfn-type=argument class=parameters | ||
| dfn-for="AnimationTrigger/removeAnimation(animation)"> | ||
|
|
||
| : <dfn>animation</dfn> | ||
| :: | ||
| The animation to disassociate from the trigger. | ||
|
|
||
| </div> | ||
|
|
||
| </div> | ||
|
|
||
| # Privacy Considerations # {#privacy-considerations} | ||
|
|
||
| There are no known privacy impacts of the features in this specification. | ||
|
|
||
Oops, something went wrong.
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.
FYI @flackr:
The idea with the
invokes deactivationflag is that EventTriggers will, when initialized, set this flag to true only if configured to have deactivation events (and leave false otherwise). TimelineTriggers always set this flag to true as they inherently have a deactivation "event".