Repository navigation
Description
Authors should be able to control whether to use the offseted or initial (non-offsetted) position for the scroll position of a sticky-positioned box.
Motivation
Sticky positioning can be used for many different use-cases.
One such use case is to add a sticky menu. When an author calls scrollIntoView() on that menu, it's enough to scroll it so that the offseted position comes into view. If the user moves focus into the menu, scrolling back to the initial non-offsetted position could be surprising.
Another use case is for "scrollytelling" such as in this modified "meet the mosters" example that I borrowed from @bramus. (I moved the monsters under the corresponding headline in the DOM). The monsters are revealed with scroll triggered animations. In this use case you want to use the initial position for the scroll position. If we use the offsetted position, the corresponding monster-text will not be scrolled into view, and the reveal animation will not be triggered.
When using scroll-driven or scroll-triggered animations it is important that we scroll to the correct position when focusing on or in a sticky positioned element.
I think only authors can know which position is correct.
History
There has been multiple issues on the scroll position of sticky-positioned boxes:
#1459 concluded with the following edit
For the purposes of any operation targetting the scroll position of a sticky positioned element (or one of its descendants), the sticky positioned element must be considered to be positioned at its initial (non-offsetted) position.
For example, if a user clicks a link targetting a sticky-positioned element, even if the element's nearest scrollport is currently scrolled such that the sticky positioned element is offset from its initial position, the scrollport will be scrolled back so that the element's initial position is visible.
This was reverted in #7930:
For the purposes of any operation targeting the scroll position of a sticky positioned element (or one of its descendants), the sticky positioned element must be considered to be at its offsetted position.
For example, if a user clicks a link targeting a sticky-positioned element, if the element's nearest scrollport is currently scrolled such that the sticky positioned element is offset from its initial position, the scroll container will be scrolled back only the minimum necessary to bring it into its desired position in the scrollport (rather than scrolling all the way back to target its original, non-offsetted position).
The TLDR, we have two options:
- Scroll to the current position - Current behavior in Chrome (without flag), Firefox and Safari.
- Scroll to the non-offsetted position - Current spec behavior implemented in Chrome behind experimental web platform features flag.
I think both are valid options, and it should be up to the author to decide which to use.
Activity