-
Notifications
You must be signed in to change notification settings - Fork 689
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
[web-animations-2][css-animations-2] What to do with keyframe offsets outside of animations. #7825
Comments
+1 for option 2 |
I suppose we expected developers to omit Then what would be the expected behavior for @keyframes fade-in-animation {
contain 0% { opacity: 0; }
contain 100% { opacity: 1; }
}
.elem {
animation: fade-in-animation;
animation-timeline: view-timeline;
animation-delay: enter 50% exit 50%;
} Does the I don't think I'd expect neither clamping nor mapping the values of one to the other. |
I think the most expected thing to do is to pin the keyframes to wherever it is they declare themselves to be, i.e. option 2. That is, raw percentages are relative to the animation duration, but absolute keyframe locations aren't. To address @ydaniv's case, once all the frames are pinned onto the timeline, we identify the start and endpoints of the animation, and if they are outside the range of the first/last frames, we pin the neutral value. And then wherever we don't have a value, we interpolate among these pinned values. |
At first I was a little bit concerned about option 2 because:
|
I was thinking that even with option 2, it would still not be allowed to have regular percentage keyframes outside of 0-100% which would mean that no existing animations would hit this. As such, this would only affect new syntaxes like keyframes linked to scroll offsets (or in the future possibly absolute times) where they may dynamically fall outside of the animation's 0 - 100% range.
These could continue to throw given regular percentage keyframes which are known to be outside of the animation bounds.
That's right, outside of the active interval it would still use the fill behaviour so it should be able to be sequenced with no issue. |
Proposed Resolution: Adopt option 2, allowing keyframes to be pinned outside the 0%-100% range and interpolating from them to find 0% and 100%. Keyframes specified at < 0% or > 100% remain invalid. |
The CSS Working Group just discussed
The full IRC log of that discussion<TabAtkins> Topic: Keyframe offsets outside of the animations<TabAtkins> github: https://github.com//issues/7825#issuecomment-1306090794 <TabAtkins> Rossen_: Proposed resolution linked in the agenda <TabAtkins> flackr: with sla, especiallyw ith dynamicly defined keyframes, you can end up with offsets outside the range <TabAtkins> flackr: Proposed solution is to allow these. They don't change the animation's active duration, but their effects still apply and just get clipped to the end of the animation duration. <TabAtkins> flackr: And allow it for classic animations too (negative %, >100%) <TabAtkins> +1 to this <TabAtkins> we allow overshoot in other places like gradients <TabAtkins> RESOLVED: Accept proposal to allow keyframes outside of the animation's duration. <TabAtkins> s/And allow/But don't allow/ <TabAtkins> s/animations too/animations, due to possible compat/ |
Fixed by #8202 |
In #7044 we #7044 (comment) to add phase linked offsets to the animations APIs. This allows tying both the animation start/end and keyframes to particular parts of the overall timeline time. However, this also allows accidentally specifying keyframe offsets which are before 0% or after 100% of the animation, e.g.
The above is obviously a mistake, though you could imagine cases if lengths or calculations are allowed (e.g. #7575) we could end up in this situation dynamically in more legitimate incidental cases, e.g.
I can think of 4 options for how to handle this:
Treat keyframes resolving outside of 0 - 100% as an error. This is what is specified in css-animations-1:
and is also specified by web-animations-1:
However, if we allow length calculated offsets, it will not be possible at animation construction time to know whether a future size of scrolling box will result in an invalid keyframe offset. Cancelling the animation seems dangerous as this state would often be ephemeral. Naively, we could simply skip the animation when this happens (the same as if the timeline was currently inactive). This could result in sudden flips in visible styles when box sizes pass this threshold.
Allow animation offsets outside of 0 - 100% and interpolate from their offset. These would not change the timing of the animation but at 0% animation progress we would interpolate between the keyframes. E.g. if a -50% keyframe specified
opacity: 0
and a 50% keyframe specifiedopacity: 1
then at 0% progress when the animation starts it would produceopacity: 0.5
. This would result in a continuous effect as the box size changed and probably matches developer expectations.To do this we would have to change the implicit from and to keyframes to only exist when we don't have a computed keyframe
<= 0%
or>= 100%
. Relevant text of css-animations-1 is:The relevant text of web-animations-1:
The challenge is that when this condition occurs is dynamic so these 0% / 100% keyframes may be needed some of the time and not other times.
Clamp calculated animation offsets outside of 0 - 100% to 0 - 100%. This is similar to the above except that when an animation offset would resolve outside of 0 - 100% it is computed to 0 or 100%. E.g. if a -50% keyframe specified
opacity: 0
and a 50% keyframe specifiedopacity: 1
then at 0% progress when the animation starts it would produceopacity: 0
as the -50% keyframe would have been clamped to 0%. This would result in a continuous effect as box sizes change, but the compressing of effects likely doesn't match developer expectations.Skip keyframes with offsets outside of 0 - 100%. When a keyframe offset computes outside of 0 - 100%, exclude that keyframe. E.g. if a -50% keyframe specified
opacity: 0
and a 50% keyframe specifiedopacity: 1
then it would be as if only the 50% keyframe were specified, so at 0% progress when the animation starts it would produce the underlying opacity through the implicit keyframe constructed by css-animations-1 or web-animations-1.My proposal would be to go with option 2 as I believe it leads to the least developer surprise and allows the effect to be continuous even as block sizes change. This is also consistent with the logic from #7432 where we resolved to not clamp the view timeline progress range to the actually scrollable range.
The text was updated successfully, but these errors were encountered: