-
Notifications
You must be signed in to change notification settings - Fork 707
[scroll-animations-1] Allow <length-percentage>
in <keyframe-selector>
when combined with <timeline-range-name>
#10000
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
Comments
<length-percentage>
in <keyframe-selector>
when combined with <timeline-range-name>
Really sensible idea. Here's a supporting example that led me here: https://codepen.io/nathanbabcock/pen/zYXmNwX The goal is to add a gradient fade effect to the top/bottom of scrolling content as a subtle indication that there's more content in that direction. It should smoothly fade out when reaching the top or bottom of the scroll container (at an absolute pixel offset proportional to the length of the fade effect). Even with Bramus' proposal above would make it possible to express all the logic underneath a single |
After reading #10879, maybe we should allow @keyframes f {
0% { translate: 0% 0%; } /* ✅ Allowed */
150px { translate: 0% -100%; } /* ❌ Not allowed */
}
el {
animation-name: f;
animation-timeline: scroll();
} (These are the keyframes for something like this shrinking header that animates using the If we don’t want this extra addition, the current proposal can already work if we enable @keyframes f {
scroll 0% { translate: 0% 0%; } /* ✅ Allowed */
scroll 150px { translate: 0% -100%; } /* ❌ Not allowed */
}
el {
animation-name: f;
animation-timeline: scroll();
} |
Feedback from @flackr, @fantasai, @tabatkins, @ydaniv, @birtles, etc would be appreciated here :) |
Since we already allowed range names in there, might as well allow length-percentage too. The whole point of that was to allow specifying points on the timeline directly as selectors, so makes sense to allow anything that can select a point on the timeline. |
/ping @graouts as he’s working on the WebKit implementation for Scroll-Driven Animations and might have input as well here. |
I was actually just looking at this yesterday. This makes sense to me. There is actually another area of difference between values accepted in the WAAPI and via CSS: the WAAPI supports double values in a 0-1 range. I don't know whether it's desirable to also add that to CSS given it's merely a convenience over percentage values. |
Great. Adding the Agenda+ label to discuss soon or at the upcoming F2F.
Seems like food for a follow-up issue :) |
I don't think there was any reason for this not to be allowed so this seems reasonable. Resolving the calculation depends on the particular target being animated though technically so do the range names in general so I think this should be fine. For the WAAPI api, rangeStart and rangeEnd accept a TimelineRangeOffset as well as a DOMString. Presumably we would accept the same for keyframe offsets so as not to require string parsing, and when reading back the value from calling getKeyframes you would presumably get the TimelineRangeOffset type. |
Is there any reason not to address this as part of #4907? It seems like that would produce a more consistent overall outcome? |
I believe the proposal in this issue is a minimal change that should not be blocked #4907 as the latter still requires a design and some further discussion about the details. I have left a comment on the issue with some things that would need some more thought. |
Right, I'm just concerned that if there's a more general solution that covers all cases in a consistent fashion, then we should do that instead of piecemeal fixes that we need to continue supporting forever and which may even prevent a better, more general approach in future. |
The CSS Working Group just discussed
The full IRC log of that discussion<emilio> bramus: this is about the syntax in the keyframe selector (currently `<percentage>` and `<timeline-range-name>`<emilio> *) <emilio> ... But in CSS you can specify `animation-range: entry calc(0% + 100px)` <emilio> ... problem is this is not allowed in keyframes <emilio> ... you can attach an animation to specified range that uses calc() <emilio> ... if you have keyframes that contains ranges <emilio> ... you can't <emilio> ... so inside `@keyframes { cover 0% { ... } }`, but you can't do `@keyframes { cover calc(...) { ... } }` <emilio> ... proposal is to change the syntax from percentage when timeline range name to also accept `<length-percentage>` <emilio> ... so that you can choose to attach one animation or keyframes with predefine range info <emilio> q+ <astearns> ack emilio <emilio> emilio: what happens if the keyframe containing pixels is attached to the doc timeline (time based) <emilio> bramus: I believe they get ignored <emilio> emilio: seems fine I guess <bramus> emilio: seems fine <TabAtkins> emilio: seems fine <bramus> emilio: seems consistent with previous issue rsolution <bramus> … as long as its well defined when it does not apply <bramus> bramus: that is already covered <emilio> PROPOSED: Allow `<length-percentage>` in keyframe selectors <emilio> bramus: not exactly <emilio> ... bigger than what I asked but could work <emilio> emilio: so you only wanted where you already have a range name <emilio> bramus: right <ydaniv> q+ <emilio> emilio: but on the previous issue we resolved that we want math functions there so allowing this seems consistent with that <bramus> `<keyframe-selector> = from | to | <length-percentage> | <timeline-range-name> <length-percentage>` <flackr> In the future, could do something like calc(50% + 1s) <bramus> bramus: so this would be the syntax then ^ <astearns> ack ydaniv <emilio> ydaniv: in order to make this apply to scroll timeline you also need plain `<length-percentage>` <bramus> bramus: not really, as we have scroll range now <emilio> bramus: not really because we decided to add the scroll range to scroll-timeline <emilio> ... but would be nice <astearns> bramus: not really <bramus> emilio: seems ok <kizu> +1 <emilio> PROPOSED: Allow `<length-percentage>` in keyframe selectors (with or without `<timeline-range-name>`) <emilio> RESOLVED: Allow `<length-percentage>` in keyframe selectors (with or without `<timeline-range-name>`) <emilio> fantasai: what about time based anims? <emilio> emilio: get ignored apparently |
The problem
With Scroll-Driven Animations, authors often want to run animations offsetted against one of the segment edges. For example, to run an animation up to "100px from the start of the range". For this, authors can do calculations in keyframe offsets, e.g.
animation-range: entry 0% entry calc(0% + 100px);
.While this syntax works perfectly fine, it is not allowed everywhere. Depending on which keyframes format authors use, they can or can’t do calculations.
@keyframes
that include range information: ❌ Not allowedThis leads to frustration, as recently expressed by Matthew Perry on Twitter:
I think we should close this gap, and allow calculated keyframes across the board.
Performing calculations in the offsets
Web Animations API
If they want to – and they often do – authors can also do calculations in the
offset
value. When passing in keyframes as an object, they can adjust the values forrangeStart
and/orrangeEnd
:However, when passing in an array of objects as the keyframes, it is not accepted.
In both snippets above, authors get back this error:
CSS Animations
Looking at the CSS variant of SDA, it’s similar there: when using
animation-range
an author can do calculations, but when creating a set of keyframes with@keyframes
they can not.The Cause
In both cases (CSS or WAAPI), this is because of the syntax of keyframe selectors. As per spec, the offsets are limited to
<percentage>
s when combined with a<timeline-range-name>
:This in contrast to
animation-range-start
andanimation-range-end
which do accept lengths (spec):Proposed Solution
Allow
<length-percentage>
– instead of only<percentage>
– in<keyframe-selector>
when combined with<timeline-range-name>
.By allowing
<length-percentage>
, authors can perform these calculations across the board, independent of which format they use to create their animation. The proposed new syntax is this:As a result, the failing code snippets listed above will start to work fine.
The text was updated successfully, but these errors were encountered: