Open flackr opened 1 month ago
We need to balance for uses where scroll marker targets may be
Proposal, when deciding whether we should select the next item, we do so when:
Note that we unfortunately cannot use the exact same logic as snap areas. Since the target may only be the header of the entire section, we should consider the effective target to be everything from the first target being aligned to the next target being aligned. We could consider re-using the snap logic using this virtual area.
The proposed algorithm sounds good at the first glance. I recently implemented something similar to it in my blog (https://blog.kizu.dev/captured-custom-properties/ for example, using scroll-driven animations, so works only in Chrome for now, source CSS behind it). I am using an inset: 50%
with the “markers” on headers, which seems to work better than any of my other attempts to do so.
The CSS Working Group just discussed [css-overflow-5] Improve active marker calculation
, and agreed to the following:
RESOLVED: Relax spec for less definitive cases, miriam to add use cases to issue, flackr to write possible algorithm(s) as examples
Currently the active scroll marker is determined by finding the target which is scrolled to or before the current scroll position. However, this means that even when the next section is 90%+ visible until it reaches the top of the scrollport (or it's scroll aligned position) the active marker does not update to this section. See https://flackr.github.io/carousel/examples/scroll-marker/scrolltarget/ for a demo of this behavior.
Instead, I propose we have the active marker calculated using logic similar to how snap areas are selected where we will select the next section if the previous target is above its desired scroll alignment and the next one is more than half-way to being aligned.
This could be analogous to snap areas where we create a virtual snap area from the start of one scroll target to the start of the next, however unlike snap areas we still want to strongly consider the previous if the next one is not yet sufficiently in view. E.g. if you're scrolled halfway through section 1 even though the target (the header) is scrolled above the viewport you should still be considered to be in section 1 until section 2 is mostly in view.