Re: [csswg-drafts] [css-animations-2][web-animations-2] How should AnimationTrigger work? (#12119)

Replying to @ydaniv's [comment](https://github.com/w3c/csswg-drafts/issues/12119#issuecomment-2913162200):

>     * Using same trigger for multiple animations is probably more common, just like you can reuse a `ViewTimeilne` for multiple animations. If it still makes the flow too complicated then I'm willing to let this go.

Good point. I think you have a much better understanding of the ergonomics and use cases of this feature than me.

>     * Having a `trigger` property on an `Animation` constructor or as property for `Element.animate()` is a very ergonomic API. Could we have that defined as another way for simply invoking the `AnimationTrigger.animations.add(animation)` procedure?

I agree.

>     * Explicitly calling playback methods will also disassociate any triggers from the animation, so, this will still force a use of some internal flag to run the corresponding procedure, to denote the disassociation, right? Though this is probably better than maintaining a state.

This is a really good point. I was thinking about this after making my proposal and it got me thinking: why do playback methods (including `cancel()`) even need to disassociate from the trigger?

If the trigger is acting at an arm's length and simply invoking `play()`, `pause()` etc. and the user interferes by calling `pause()` / `play()` etc. then the result is whatever you'd get if you called `play()` / `pause()` in that same sequence. If the user wants the trigger to no longer apply, they can disassociate it.

My original concern about `cancel()` not cancelling things would still be addressed in this model since `cancel()` would work as usual. The only caveat is that if the user later scrolled etc. the animation might start whereas if `cancel()` disassociated triggers, that would no longer happen.

I'm not sure but I think having less magic and less coupling might be preferable.

>     * I like the idea of constructed `Animation`'s simply not having a trigger and just keep work as is, while CSS and `.animate()` ones get a new instance of the default trigger. Does that summarize this point correctly?

I'm not sure that `animate()` needs a default trigger. I'm not sure CSS does either unless that makes the mapping to CSS default property values simpler.

-- 
GitHub Notification of comment by birtles
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/12119#issuecomment-2920976649 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Friday, 30 May 2025 01:29:39 UTC