w3c / w3c/csswg-drafts

[web-animations-2] Animate - Add more event handlers

Open
#6,166 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

web-animations-2
Dominant language
Bikeshed
Stars
4.9k
Forks
816
PR merge metrics
PR metrics pending

Description

Ref: https://drafts.csswg.org/web-animations-1/#the-animation-interface

Could these proposed event handlers be added to the Animation interface?

onstart

Example/proposal: https://jsfiddle.net/glenn2223/gj7heoLv/

Details
The event handler for each time the animation starts

Reason
In case someone wants to change the state it starts, as they can currently do when it finishes.
Currently, as per the example, setting any state before the calling play() causes issues when there is a delay or endDelay


onAnimationStart - possible handler. Maybe a higher preference to the onKeyFrame handler?

Details
This would fire on (or just before) the first frame being initiated (or the implied first frame in the case of implicit to/from keyframes)

Reason
To fire an event the second that the animation actually starts (after delays)


onAnimationFinish - possible handler. Maybe a higher preference to the onKeyFrame handler?

Details
This would fire on (or just after) the last frame being initiated (or the implied last frame in the case of implicit to/from keyframes)

Reason
To fire an event the second that the animation actually ends (before delays)


onKeyFrame (index: number)

Proposal: https://jsfiddle.net/glenn2223/uwg589Lx/

Details
This would fire on each keyframe that is hit, passing the index of the keyframe

Reason
You can fire events at certain stages of the animation process as per the details in the proposal link just above.


Also, is there a way to detect if it's actually running or just delayed? I saw the AnimationPlayState enumeration but that doesn't;t have a startDelay or endDelay state.

I only ask because if it's delayed I'd rather call cancel() but if it's running I'd rather call finish()

(Should I open a new issue)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Animation interface in the Web Animations specification and review the linked CSSWG draft and JSFiddle proposals. Compare the requested onstart, onAnimationStart, onAnimationFinish, and onKeyFrame handlers with the existing AnimationPlayState behavior. Done means the event-handler design and delayed-versus-running behavior are resolved in the specification.

Written by the indexing model from the issue text.

Assessment

Tech stack
css, javascript
Domain
frontend, web-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.