1.Introduction
This section is not normative.
A content author does not necessarily wantscroll chainingto occur for allscroll
containers.Somescroll containersmay be part of acontaining block chainbut may
serve a different logical purpose in the document and may want to prevent scrolling from continuing
up thescroll chain.To achieve this, a content author will install event listeners without
thepassive flagset and will usepreventDefault()
when there is a risk that scroll
chaining will occur. This is detrimental for the following reasons:
-
The user agent may in the future introduce new input methods for scrolling that are not supported by the content author’s event listeners.
-
A non passive event listener will delay scrolling because the user agent will have to wait for the result of the event listener to determine if
preventDefault()
was called causing increased scroll latency. -
When scrolling is performed near the edge of thescroll boundary,thedefault actionmay cause both scrolling to the edge of thescroll containerand aboundary default action.Calling
preventDefault()
will not only cancel theboundary default actionbut also the scroll to the edge of thescrollport. -
Thedefault actionfor the event may also provide additional behavior that the author does not want to cancel such as an overscroll affordance.
preventDefault()
doesn’t allow the content author to cancel only some of thedefault actionssuch as scroll chaining.
Thus, it is not possible for a content author to controlscroll chainingand overscroll in a robust, performant and forward compatible way. Theoverscroll-behaviorproperty fixes this shortcoming.
1.1.Value Definitions
This specification follows theCSS property definition conventionsfrom[CSS2]using thevalue definition syntaxfrom[CSS-VALUES-3]. Value types not defined in this specification are defined in CSS Values & Units[CSS-VALUES-3]. Combination with other CSS modules may expand the definitions of these value types.
In addition to the property-specific values listed in their definitions, all properties defined in this specification also accept theCSS-wide keywordsas their property value. For readability they have not been repeated explicitly.
2.Motivating Examples
#sidebar{ overscroll-behavior : contain; }
In this case, the author can usecontainon the sidebar to prevent scrolling from being chained to the parent document element.
html{ /* only disable pull-to-refresh but allow swipe navigations */ overscroll-behavior-y: contain; }
In this case, the author can usecontainon the viewport defining element to prevent overscroll from triggering navigation actions.
#infinite_scroller{ overscroll-behavior-y : none; }
In this case the author can usenoneon the infinite scroller to prevent both scroll chaining and overscroll affordance.
3.Scroll chaining and boundary default actions
Operating Systems have rules for scrolling such as scroll chaining and overscroll affordances. This specification does not mandate if and how scroll chaining or overscroll affordances be implemented. This specification only allows the content author to disable them if any are implemented.
Scroll chainingis when scrolling is propagated from onescroll containerto an ancestorscroll containerfollowing thescroll chain.Typically scroll chaining is performed starting at the event target recursing up thecontaining block chain.When ascroll containerin this chain receives a scroll event or gesture it may act on it and/or pass it up the chain. Chaining typically occurs when thescrollporthas reached its boundary.
Ascroll chainis the order in which scrolling is propagated from onescroll containerto another. Theviewportparticipates inscroll chainingas the document’sscrollingElement,both regarding placement in the scroll chain as well as adhering to the chaining rules applied to it.
Scroll boundaryrefers to when the scroll position of ascroll containerreaches the edge of thescrollport.If a scroll container has no potential to scroll, because it does notoverflowin the direction of the scroll, the element is always considered to be at the scroll boundary.
Boundary default actionrefers to the user-agent-defineddefault actionperformed when scrolling against the edge of thescrollport.Alocal boundary default actionis aboundary default actionwhich is performed on thescroll containerwithout interacting with the page, for example displaying a overscroll UI affordance. Conversely, anon-local boundary default actioninteracts with the page, for example scroll chaining or a navigation action.
4.Overscroll Behavior Properties
Theoverscroll behaviorcontrols the permittedboundary default actionfor ascroll containerelement when itsscrollportreaches the boundary of its scroll box.
Theoverscroll-behaviorproperty specifies theoverscroll behaviorfor ascroll containerelement. It allows the content author to specify that ascroll containerelement must prevent scroll chaining and/or overscroll affordances.
An element that is notscroll containermust accept but ignore the values of this property. This property must be applied to all scrolling methods supported by the user agent.
Note:This property should provide guarantees that are, at least, as strong aspreventDefaultfor preventing both scroll chaining and overscroll. Doing otherwise would cause content authors to usepreventDefaultinstead.
Name: | overscroll-behavior |
---|---|
Value: | [ contain|none|auto ]{1,2} |
Initial: | auto auto |
Applies to: | scroll containerelements |
Inherited: | no |
Percentages: | n/a |
Computed value: | see individual properties |
Canonical order: | per grammar |
Animation type: | discrete |
Media: | visual |
Theoverscroll-behaviorproperty is a shorthand property that sets the specified values ofoverscroll-behavior-xandoverscroll-behavior-yin that order. If only one value is specified, the second value defaults to the same value.
Values have the following meanings:
- contain
- This value indicates that the element must not performnon-local boundary default actionssuch as scroll chaining or navigation. The user agent must not perform scroll chaining to any ancestors along thescroll chainregardless of whether the scroll originated at this element or one of its descendants. This value must not modify the behavior of howlocal boundary default actionsshould behave, such as showing any overscroll affordances.
- none
- This value implies the same behavior ascontainand in addition this element must also not performlocal boundary default actionssuch as showing any overscroll affordances.
- auto
- This value indicates that the user agent should perform the usualboundary default actionwith respect toscroll chaining,overscroll and navigation gestures.
Note:In the case where a user agent does not implement scroll chaining and overscroll affordances, these values will have no side effects for a compliant implementation.
Note:Programmatic scrolling is clamped and can not trigger anyboundary default actions.
4.1.Overscroll and Positioned Elements
This specification does not generally dictate what, if any, "overscroll" or similar actions might occur as alocal boundary default action.
However, if a user agentdoesuse "overscroll" behavior (that is, allowing a scrollable element to be scrolled slightly "past the end" of its scrollable area, usually with a "rubber-banding" effect after the scroll or drag is completed), then the following applies:
If an element usesfixed positioningand is positioned relative to theinitial containing block, or is asticky positionedelement which is currently stuck to theviewport, then when theroot scrollerexperiences "overscroll", that elementmust notoverscroll with the rest of the document’s content; it must instead remain positioned as if the scroller was at its minimum/maximum scroll position, whichever it will return to when the overscroll is finished.
Even tho this can visually shift the fixed/sticky element
relative to other elements on the page,
it must be treated purely as a visual effect,
and not reported as an actual layout/position change
to APIs such asgetBoundingClientRect()
.
Note:This behavior is because fixpos and viewport-stuck stickypos elements are positioned relative to "the viewport", which is conceptually above the root scroller in the page hierarchy (effectively, it’s thescroll containerholding the root scroller). Thus, overscrolling the root scroller shouldn’t have any effect on them, just like how an abspos that is a child of a scroller but whose abspos containing block isabovethe scroller isn’t affected by the scroller doing anything at all, including overscroll.
4.2.Physical Longhands foroverscroll-behavior
Name: | overscroll-behavior-x,overscroll-behavior-y |
---|---|
Value: | contain|none|auto |
Initial: | auto |
Applies to: | scroll containerelements |
Inherited: | no |
Percentages: | N/A |
Computed value: | as specified |
Canonical order: | per grammar |
Animation type: | discrete |
Logical property group: | overscroll-behavior |
Media: | visual |
Theoverscroll-behavior-xproperty specifies theoverscroll behaviorin the horizontal axis and theoverscroll-behavior-yproperty specifies theoverscroll behaviorin the vertical axis. When scrolling is performed along both the horizontal and vertical axes at the same time, theoverscroll behaviorof each respective axis should be considered independently.
4.3.Flow-relative Longhands foroverscroll-behavior
Name: | overscroll-behavior-inline,overscroll-behavior-block |
---|---|
Value: | contain|none|auto |
Initial: | auto |
Applies to: | scroll containerelements |
Inherited: | no |
Percentages: | N/A |
Computed value: | as specified |
Canonical order: | per grammar |
Animation type: | discrete |
Logical property group: | overscroll-behavior |
Media: | visual |
These properties correspond to theoverscroll-behavior-xandoverscroll-behavior-yproperties. The mapping depends on the element’swriting-mode.