Skip to content
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

[scroll-animations-1] Allow optional <percentage> in animation-range-* #8438

Closed
cdoublev opened this issue Feb 9, 2023 · 11 comments
Closed
Labels
Closed Accepted by CSSWG Resolution Commenter Satisfied Commenter has indicated satisfaction with the resolution / edits. scroll-animations-1 Current Work

Comments

@cdoublev
Copy link
Collaborator

cdoublev commented Feb 9, 2023

If I understand correctly, the <percentage> in animation-range-start and animation-range-end refers to a specified point on the timeline. Currently, when declaring animation-range with a single <timeline-range-name>:

If a <timeline-range-name> alone is specified, animation-range-start is set to that name plus 0% and animation-range-end is set to that name plus 100%.

So I wonder why animation-range-start and animation-range-end do not allow <percentage> to be optional:

  Name:	animation-range-start 
- Value:	[ normal | <timeline-range-name> <percentage> ]#
+ Value:	[ normal | <timeline-range-name> <percentage>? ]#

It would default to 0% in animation-range-start and 100% in animation-range-end.

Also, I guess this <percentage> should be restricted to [0,100], so <percentage [0,100]>, as well as in <keyframe-selector>.

I also wonder if:

  • <percentage> should always be lower in animation-range-start than in animation-range-end
  • normal should not be allowed to repeat
  • it would be more intuitive to expand animation-range: timeline-1 5% to animation-range-start: timeline-1 5%; animation-range-end: timeline-1 100% (instead of animation-range-start: timeline-1 5%; animation-range-end: normal
  • <timeline-range-name> is inappropriate in <keyframe-selector> because I think animation-range defines an interval for all keyframes and an author is not supposed to declare eg. timeline-a 0% {} timeline-b 100% {} with animation-range: timeline-x

But these questions might deserve their own issue and I realize that these properties are currently under discussion so they may be a bit premature.

@flackr
Copy link
Contributor

flackr commented Mar 10, 2023

It would default to 0% in animation-range-start and 100% in animation-range-end.

This seems fine to me.

Also, I guess this <percentage> should be restricted to [0,100], so <percentage [0,100]>, as well as in <keyframe-selector>.

Discussed in #8552 already. I don't think there's any need to restrict things and allowing percentages < 0 or > 100% allows for specifying more cases, e.g. exit -10% starts 10% before the exit range starts.

I also wonder if:

  • <percentage> should always be lower in animation-range-start than in animation-range-end

This can't be enforced if they're in different ranges and in many cases whether one is before the other or not will be dynamic, e.g. contain 0% is usually after entry-crossing 99% but not if the element is larger than the viewport.

TLDR I don't think we should try to enforce ordering and just let the math work out as it does. If you specify a 0 range then you'll have an animation that is always inactive.

  • normal should not be allowed to repeat

Why not? We don't disallow things like overflow: hidden hidden;

  • it would be more intuitive to expand animation-range: timeline-1 5% to animation-range-start: timeline-1 5%; animation-range-end: timeline-1 100% (instead of animation-range-start: timeline-1 5%; animation-range-end: normal

I've actually wondered whether it would be more intuitive for a single value range name / offset to be treated as an inset on the range. E.g. Expand animation-range: range-name 5% to animation-range-start: range-name 5%; animation-range-end: range-name calc(100% - 5%). Typically single value shorthands expand to the same value applied to all longhands but that would result in 0 range which is probably never what you want unless you're using it as a trigger point.

  • <timeline-range-name> is inappropriate in <keyframe-selector> because I think animation-range defines an interval for all keyframes and an author is not supposed to declare eg. timeline-a 0% {} timeline-b 100% {} with animation-range: timeline-x

The range name is not naming a timeline, it's a named range within a timeline. This is setting the start and end points of the animation. It is valid for particular keyframes to be further refined to other phases. For example you could specify

@keyframes frames {
  contain 0% { transform: translateY(-10px); } /* contain 0% is equivalent to 0% given the animation-range. */
  exit 0% { transform: none; opacity: 1; }
  exit 100% { opacity: 0; } /* technically exit 100% is equivalent to 100% given the animation-range. */
}

.animate {
  animation: frames;
  animation-timeline: view();
  animation-range: contain 0% cover 100%;
}

But these questions might deserve their own issue and I realize that these properties are currently under discussion so they may be a bit premature.

Yes, these probably should be separate.

@fantasai
Copy link
Collaborator

I've actually wondered whether it would be more intuitive for a single value range name / offset to be treated as an inset on the range.

@flackr This is a super interesting idea. Should we spec it? :)

@fantasai
Copy link
Collaborator

Summary of proposed changes:

  • Make <percentage> optional in animation-range-start/end, defaulting to 0%/100%.
  • If animation-range: name x% is specified, expand it to animation-range-start: name x%; animation-range-end: name (100 - x)%. (Current spec expands to animation-range-start: name x%; animation-range-end: normal.)

@ydaniv
Copy link
Contributor

ydaniv commented Mar 11, 2023

If we consider having defaults of 0%/100% I think it would be more useful to expand range-name 5% to range-name 5% range-name 100%.
I think this sort of symmetry is very interesting specifically for cover or even contain, but less so for the others.

@cdoublev
Copy link
Collaborator Author

Thanks for the clarifications, some points were confused in my mind. I have re-read the entire spec but have no preference on which of the default values I would prefer (100% vs. calc(100% - <animation-range- start>)).

@css-meeting-bot
Copy link
Member

The CSS Working Group just discussed [scroll-animations-1] Allow optional `<percentage>` in `animation-range-*` , and agreed to the following:

  • RESOLVED: Make <percentage> optional in animation-range-start/end, defaulting to 0%/100%
  • RESOLVED: When specifying "animation-range: foo X%", set the -range-end to "foo 100%" (staying in same phase, just setting to end)
The full IRC log of that discussion <fantasai> -> https://github.com//issues/8438#issuecomment-1464672747
<TabAtkins> fantasai: there was discussion about %s in teh syntax of animation-range
<TabAtkins> fantasai: Can specify the shorthand to a name, but the longhands currently require a %
<TabAtkins> fantasai: One proposal is to make that optional - if omitted it defaults to 0%/100% depending on prop
<TabAtkins> flackr: sounds fine to me
<bramus> +1
<TabAtkins> TabAtkins: +1
<TabAtkins> astearns: proposed resolution is to make % optional in animation-range-start/end, defaulting to 0%/100%
<fantasai> PROPOSAL: Make <percentage> optional in animation-range-start/end, defaulting to 0%/100%
<TabAtkins> RESOLVED: Make <percentage> optional in animation-range-start/end, defaulting to 0%/100%
<fantasai> animation-range: name x%
<TabAtkins> fantasai: if yous pecify `animation-range: name %`, currently it sets animation-range-start to that, and leaves -end as normal
<fantasai> animation-range-start: name x%; animation-range-end: normal
<fantasai> animation-range-start: name x%; animation-range-end: name (100 - x)%
<TabAtkins> fantasai: The alternative is to expand it to this ^^
<TabAtkins> fantasai: so if you say "contain 5%", it'll set them to "contain 5%" and "contain 95%", so you're insetting from either end
<TabAtkins> flackr: I put this forward bc it felt odd to take the specified % from the start, but ending in a potentially totally different animation range
<ydaniv> q+
<TabAtkins> flackr: felt consistent with margin/padding that get spammed to the other side of the block.
<astearns> ack ydaniv
<TabAtkins> ydaniv: q is do we want to change the range as well - if start is "entry" do we use "exit" in the end?
<TabAtkins> fantasai: Seems maybe too magical? Don't you want contain/cover?
<TabAtkins> YehonatanDaniv: For those the proposal makes sense. Seems funky that for entry 5% we expand to entry 95%
<TabAtkins> flackr: You can already use 'contain' to do that, but there are use-cases for keeping it in the same range. So i'd prefer not to.
<TabAtkins> fantasai: I'd understand if you wanted to expand "name X%" to "name X%" and "name 100%"
<TabAtkins> fantasai: so we'd take the name and set it to both longhands, but only use the % in start
<flackr> animation-range-start: name x%; animation-range-end: name 100%
<fantasai> animation-range: name x%
<fantasai> 1) animation-range-start: name x%; animation-range-end: normal
<fantasai> 2) animation-range-start: name x%; animation-range-end: name (100 - x)%
<fantasai> 3) animation-range-start: name x%; animation-range-end: name 100%
<TabAtkins> (this was gonna be my suggestion too - if the concern is just that setting 'end' to an unrelated phase, it seems reasonable to just set to that phase with 100%)
<TabAtkins> flackr: good with 2 or 3
<TabAtkins> fantasai: Slight pref for 3, okay with 2
<TabAtkins> TabAtkins: prefer 3
<TabAtkins> emilio: Also prefer 3
<TabAtkins> emilio: 2 seems too magic
<fantasai> TabAtkins: particularly, I don't know what 2 would do if you start at 55% :)
<TabAtkins> astearns: Do we think we'll get a second % in animation-range at some point?
<TabAtkins> fantasai: You can specify "name % name %" to end wherever you want
<TabAtkins> fantasai: In theory we could say "name % %" default to the previous name
<ydaniv> staying with 3 (:
<TabAtkins> astearns: If we already have the syntax, no need to complicate until people ask for it
<TabAtkins> astearns: So seems like we have option 3 consensus
<TabAtkins> RESOLVED: When specifying "animation-range: foo X%", set the -range-end to "foo 100%" (staying in same phase, just setting to end)
<fantasai> ACTION: file issue on 3-value syntax

@fantasai
Copy link
Collaborator

OK, edits are in f4a3db2. I added an example with the implications:

animation-range: entry 10% exit 90%;
animation-range-start: entry 10%;
animation-range-end: exit 90%;

animation-range: entry;
animation-range-start: entry 0%;
animation-range-end: exit 100%;

animation-range: 10%;
animation-range-start: 10%;
animation-range-end: normal;

animation-range: entry 10% exit;
animation-range-start: entry 10%;
animation-range-end: exit 100%;

animation-range: 10% exit 90%;
animation-range-start: 10%;
animation-range-end: exit 90%;

animation-range: entry 10% 90%;
animation-range-start: entry 10%;
animation-range-end: 90%;

The last three are fallout from defining the shorthand as <'animation-range-start'> <'animation-range-end'>?, so rather than trying to carve out those cases as invalid I left them in. We could define some custom handling that takes any single timeline name and duplicates it, which would make entry 10% 90% equivalent to entry 10% entry 90%--but this would mean that a number of longhand combinations have no valid serialization. @cdoublev @flackr @ydaniv Let me know if this is satisfactory, and if so I'll close the issue; otherwise lmk what you think needs further adjustment. :)

@cdoublev
Copy link
Collaborator Author

We could define some custom handling that takes any single timeline name and duplicates it, which would make entry 10% 90% equivalent to entry 10% entry 90%--but this would mean that a number of longhand combinations have no valid serialization.

It could be fixed by defining normal as a <timeline-name>, no?

I do not feel legitimate to give an opinion. You are much more invested in this spec than I am. That said it looks good to me, perhaps minus this potential typo:

  animation-range: entry;
  animation-range-start: entry 0%;
-  animation-range-end: exit 100%;
+  animation-range-end: entry 100%;

@ydaniv
Copy link
Contributor

ydaniv commented Apr 2, 2023

Thanks @fantasai, I'd like to offer another option for omitted name. Since the complete timeline interval is represented by cover we may consider treating a <percentage> with omitted names as cover <percentage>.

So that entry 60% 50% becomes entry 60% cover 50%.
Also 20% 80% can become valid as cover 20% cover 80%.
Of course this could also lead into an invalid timeline in case of end > start, but I think that's fine.
WDYT? (@flackr @bramus)

@cdoublev your change suggestion above seems correct.

fantasai added a commit that referenced this issue Apr 3, 2023
@fantasai
Copy link
Collaborator

fantasai commented Apr 3, 2023

@cdoublev Thanks, fixed the error.

I do not feel legitimate to give an opinion.

You're thinking through the implications and giving well-informed opinions, so imho your opinion is just as legitimate as mine. :) I have a bit more experience, so I have an advantage in being able to draw from that, but what matters here is how well a suggestion is thought through. And I think in that respect, your feedback is very helpful.

Since the complete timeline interval is represented by cover we may consider treating a <percentage> with omitted names as cover <percentage>.

@ydaniv This wouldn't generalize to things other than View Timelines (which might no have a cover range). So I think if we want to go in this direction of giving unnamed <percentage> values a “range name”, using normal would make more sense.

@fantasai
Copy link
Collaborator

fantasai commented Apr 3, 2023

OK, I opened a separate issue for the 3-value shorthanding question at #8672. Going to close out this one since I think we're basically done with the original issue? (Re-open if you think I missed something else.)

@fantasai fantasai closed this as completed Apr 3, 2023
@fantasai fantasai added Commenter Satisfied Commenter has indicated satisfaction with the resolution / edits. and removed Commenter Response Pending labels Apr 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Closed Accepted by CSSWG Resolution Commenter Satisfied Commenter has indicated satisfaction with the resolution / edits. scroll-animations-1 Current Work
Projects
None yet
Development

No branches or pull requests

7 participants