Skip to content

[css-animations-2][css-transitions-2] Add animation object to animation/transition events. #9010

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
flackr opened this issue Jun 27, 2023 · 9 comments

Comments

@flackr
Copy link
Contributor

flackr commented Jun 27, 2023

Currently the css-animations-1 AnimationEvent and the css-transitions-1 TransitionEvent only provide details about the animation (its name, and timing) or transition (property and timing), but if you wanted to get the actual Animation object you would have to call getAnimations() on the element and find the corresponding animation. E.g.

element.addEventListener('animationstart', (evt) => {
  // evt does not contain the animation so we have to find it.
  let animation = element.getAnimations().find(anim => anim.animationName == evt.animationName);
});

If the same animation name is started twice, e.g. animation: keyframes 1s, keyframes 1s, the developer doesn't have any way to know which Animation object in the getAnimations list corresponds to the AnimationEvent.

I propose we add the web-animations Animation object for the animation / transition to these events so that developers can easily get the associated Animation from the events. I'd propose calling it animation in both interfaces though we could consider calling it transition in the TransitionEvent interface even though the type would be Animation.

@bramus
Copy link
Contributor

bramus commented Jun 27, 2023

Very much in favor of this. Surprised me it didn’t already give authors the full details.

@flackr
Copy link
Contributor Author

flackr commented Jun 27, 2023

@birtles FYI

@ydaniv
Copy link
Contributor

ydaniv commented Jun 27, 2023

Wow, super needed! I was trying for sometime to think how to do that with the missing animation.id, which you only get for WAAPI, but this is much better (:

@birtles
Copy link
Contributor

birtles commented Jun 28, 2023

Sounds great. AnimationPlaybackEvents already expose this through their target property.

@bramus
Copy link
Contributor

bramus commented Aug 14, 2023

Since we’re all in agreement, let’s try and get an async resolution. Proposed resolutions (rewritten from what flackr@ said above) are:

  1. Add the web-animations Animation object for the animation / transition to the animation*/transition* events
  2. Name the property animation

/ping @astearns

@bramus bramus added the Async Resolution: Proposed Candidate for auto-resolve with stated time limit label Aug 14, 2023
@astearns
Copy link
Member

Restating the resolution to make sure I am understanding correctly (thumbs up if this is good, please reply with a correction if I am wrong)

Proposed Resolution: Add an animation property to the animation*/transition* events that contains the relevant Animation object

@astearns
Copy link
Member

The CSSWG will automatically accept this resolution one week from now if no objections are raised here. Anyone can add an emoji to this comment to express support. If you do not support this resolution, please add a new comment.

Proposed Resolution: Add an animation property to the animation*/transition* events that contains the relevant Animation object

@astearns astearns added Async Resolution: Call For Consensus Resolution will be called after time limit expires and removed Async Resolution: Proposed Candidate for auto-resolve with stated time limit labels Aug 22, 2023
@birtles
Copy link
Contributor

birtles commented Aug 23, 2023

(Non-substantive clarification to the resolution: the types of the animation property for animation*/transition* events should be CSSAnimation and CSSTransition respectively.)

@astearns
Copy link
Member

astearns commented Sep 3, 2023

RESOLVED: Add an animation property to the animation*/transition* events that contains the relevant Animation object (CSSAnimation and CSSTransition respectively)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants