Open bramus opened 9 months ago
document.documentElement.getAnimations
would make this simpler and also work with scoped transitions. Does that suffice?
I'm ok with adding it to VT as well.
document.documentElement.getAnimations
would make this simpler and also work with scoped transitions. Does that suffice?
This doesn’t work because the result of this doesn’t include the animations attached to the pseudos. For HTMLElement.geAnimations()
to return anything usable here you’d need to get the animations from the subtree by calling document.documentElement.getAnimations({ subtree: true });
.
However, that way you would get you all animations from the entire subtree and you’d to manually check things again.
Another approach would be something like document.documentElement.getAnimations({ pseudo: "::view-transition", subtree: true });
which would only get the subtree of the ::view-transition
pseudo. That doesn't currently exist, but it's similar to getComputedStyle(element, pseudo)
I prefer ViewTransition#getAnimations()
over document.documentElement.getAnimations({ pseudo: "::view-transition", subtree: true });
as with the former you can pass the ViewTransition
object into any method and it can get the animations from it. With the latter you’d also need to pass in the element on which you triggered the VT.
(Which reminds me: we might also need a ViewTransition#getTransitionRoot()
– or a readonly property that exposes it – once we have scoped transitions)
FWIW, I agree with ViewTransition.getAnimations()
, it's just the Element.getAnimations()
with a pseudo option is more general. I can't really think of any use cases for it though.
I agree that transition root is something that's useful. Would then viewtransition.getTransitionRoot().getAnimations({ pseudo: "::view-transition", subtree: true })
work? :)
Would then
viewtransition.getTransitionRoot().getAnimations({ pseudo: "::view-transition", subtree: true })
work? :)
That could work indeed :)
^ I like @vmpstr's suggestion above. So there's 2 independent proposals here:
Should we defer on 2 until scoped transitions starts being spec'd? As it stands today this would always return the document element.
+1 to @vmpstr's suggestion. Is the prior art pseudoElement
or pseudo
? Would be nice to be consistent if there's some prior art, otherwise pseudoElement
is my preferred name.
The only one I can think of is getComputedStyle
, whose 2nd argument is named pseudoElt
.
Nit: shouldn't getting the root be a property? like viewTransition.transitionRoot
? Kind of like getting Element.shadowRoot
Nit2: if we're extending Element.getAnimations()
, how about adding a general selector
property instead?
how about adding a general
selector
property instead?
can you expand on that. I didn't follow. :)
Pinging @flackr as this steps into web-animations-1 territory. Start reading from this comment onwards.
how about adding a general selector property instead?
can you expand on that. I didn't follow. :)
Since we're setting subtree: true
and we're getting animations from the entire subtree, use a selector to filter the elements from the subtree, instead of naming a single pseudo element.
I think that could be handy in general.
^ ah. I'm not opposed to that. But I favour adding a pseudo element option for consistency with other script APIs which similarly allow passing a pseudo element option.
As for naming, let's use the same keyword as element.animate : pseudoElement. Especially because all other API surfaces for animations use that.
it's just the Element.getAnimations() with a pseudo option is more general. I can't really think of any use cases for it though.
I could see this being useful to get the animations running on e.g. the ::before
pseudo.
I'm in favour of @vmpstr's proposal. The pseudoElement attribute was added specifically for synergy with the getComputedStyle API for accessing pseudos so this further aligns the two APIs.
how about adding a general selector property instead?
can you expand on that. I didn't follow. :)
Since we're setting
subtree: true
and we're getting animations from the entire subtree, use a selector to filter the elements from the subtree, instead of naming a single pseudo element. I think that could be handy in general.
Adding a generic selector filter is a pretty substantial additional bit of complexity for which you can usually use the querySelectorAll API, e.g. elem.querySelectorAll(query).map(e => e.getAnimations())
, where specifying the pseudo is just giving you a way to specify the actual node for your getAnimations call in a similar way to getComputedStyle, where we also don't have a generic selector.
The CSS Working Group just discussed [view-transitions-2] Add method to get all animations of a ViewTransition object
, and agreed to the following:
RESOLVED: Add a pseudoElement option to the element.getAnimations() dict arg. subtree:true/false acts on that pseudo as the root
RESOLVED: Add .transitionRoot readonly property to VT object, reflectring the element hosting the VT.
This is a side-issue to https://github.com/w3c/csswg-drafts/issues/9901 where this demo was mentioned.
To make this work, I basically need to hijack all animations and either pause them (when manually updating their
currentTime
) or give them non-DocumentTimeline
s (when attaching them to aScrollTimeline
).The code to get all these animations is this:
While this works, it’s not very ergonomic. Therefore I’m suggesting something like
ViewTransition.getAnimations()
to easily get them:This would also benefit Scoped Transitions, where you can have multiple View Transitions going on at once.