|
| 1 | +<pre class='metadata'> |
| 2 | +Title: CSS Overscroll Behavior Module Level 1 |
| 3 | +Shortname: overscroll-behavior |
| 4 | +Level: 1 |
| 5 | +Status: CG-DRAFT |
| 6 | +Work Status: Exploring |
| 7 | +Group: WICG |
| 8 | +URL: https://wicg.github.io/overscroll-behavior/ |
| 9 | +Repository: wicg/overscroll-behavior |
| 10 | +Editor: Benoit Girard, Facebook, bgirard@fb.com |
| 11 | +Abstract: This module defines 'overscroll-behavior' to control the behavior when the scroll position of a <a>scroll container</a> reaches the edge of the <a>scrollport</a>. |
| 12 | +Abstract: This allows content authors to hint that the <a>boundary default actions</a>, |
| 13 | +Abstract: such as scroll chaining and overscroll, should not be triggered. |
| 14 | +</pre> |
| 15 | + |
| 16 | +<pre class='anchors'> |
| 17 | +urlPrefix: https://www.w3.org/TR/css-display-3/ |
| 18 | + type: dfn; text: containing block chain |
| 19 | +url: https://drafts.csswg.org/css-overflow-3/#scroll-container |
| 20 | + type: dfn; text: scroll container |
| 21 | + type: dfn; text: scroll containers |
| 22 | +url: https://www.w3.org/TR/uievents/#default-action |
| 23 | + type: dfn; text: default action |
| 24 | + type: dfn; text: default actions |
| 25 | +url: https://dom.spec.whatwg.org/#dom-event-preventdefault |
| 26 | + type: dfn; text: preventDefault |
| 27 | +url: https://dom.spec.whatwg.org/#dom-eventtarget-addeventlistener |
| 28 | + type: dfn; text: passive flag |
| 29 | + |
| 30 | +</pre> |
| 31 | + |
| 32 | +Introduction {#intro} |
| 33 | +===================== |
| 34 | + |
| 35 | +<em>This section is not normative.</em> |
| 36 | + |
| 37 | +A content author does not necessarily want <a>scroll chaining</a> to occur for all <a>scroll |
| 38 | +containers</a>. Some <a>scroll containers</a> may be part of a <a>containing block chain</a> but may |
| 39 | +serve a different logical purpose in the document and may want to prevent scrolling from continuing |
| 40 | +up the <a>scroll chain</a>. To achieve this, a content author will install event listeners without |
| 41 | +the <a>passive flag</a> set and will use <a>preventDefault</a> when there is a risk that scroll |
| 42 | +chaining will occur. This is detrimental for the following reasons: |
| 43 | + |
| 44 | +* The user agent may in the future introduce new input methods for scrolling that are not supported |
| 45 | + by the content author's event listeners. |
| 46 | +* A non passive event listener will delay scrolling because the user agent will have to wait for the |
| 47 | + result of the event listener to determine if <a>preventDefault</a> was called causing increased |
| 48 | + scroll latency. |
| 49 | +* When scrolling is performed near the edge of the <a>scroll boundary</a>, the <a>default action</a> |
| 50 | + may cause both scrolling to the edge of the <a>scroll container</a> and a <a>boundary default |
| 51 | + action</a>. Calling <a>preventDefault</a> will not only cancel the <a>boundary default action</a> |
| 52 | + but also the scroll to the edge of the <a>scrollport</a>. |
| 53 | +* The <a>default action</a> for the event may also provide additional behavior that the author does |
| 54 | + not want to cancel such as an overscroll affordance. <a>preventDefault</a> doesn't allow the |
| 55 | + content author to cancel only some of the <a>default actions</a> such as scroll chaining. |
| 56 | + |
| 57 | +Thus, it is not possible for a content author to control <a>scroll chaining</a> and overscroll in a |
| 58 | +robust, performant and forward compatible way. The 'overscroll-behavior' property fixes this |
| 59 | +shortcoming. |
| 60 | + |
| 61 | + |
| 62 | +Motivating Examples {#motivating-examples} |
| 63 | +================= |
| 64 | + |
| 65 | + |
| 66 | +<div class=example> |
| 67 | +A position fixed left navigation bar does not want to hand off scrolling to the document because a |
| 68 | +scroll gesture performed on the navigation bar is almost never meant to scroll the document. Note |
| 69 | +that using the native overscroll affordances are still desirable while scroll chaining is to be |
| 70 | +prevented. |
| 71 | + |
| 72 | + <pre class="lang-css"> |
| 73 | + #sidebar { |
| 74 | + overscroll-behavior: contain; |
| 75 | + } |
| 76 | + </pre> |
| 77 | + |
| 78 | +In this case, the author can use <a value for=overscroll-behavior>contain</a> on the sidebar to |
| 79 | +prevent scrolling from being chained to the parent document element. |
| 80 | +</div> |
| 81 | + |
| 82 | +<div class=example> |
| 83 | +A page wants to implement their own pull-to-refresh effect and thus needs to disable browser |
| 84 | +native overscroll action. |
| 85 | + |
| 86 | + <pre class="lang-css"> |
| 87 | + html { |
| 88 | + /* only disable pull-to-refresh but allow swipe navigations */ |
| 89 | + overscroll-behavior-y: contain; |
| 90 | + } |
| 91 | + </pre> |
| 92 | + |
| 93 | +In this case, the author can use <a value for=overscroll-behavior>contain</a> on the viewport |
| 94 | +defining element to prevent overscroll from triggering navigation actions. |
| 95 | +</div> |
| 96 | + |
| 97 | +<div class=example> |
| 98 | +A infinite scrollers loads more content as user reaches the boundary and thus wants to disable the |
| 99 | +potentially confusing rubber banding effect in addition to scroll chaining. |
| 100 | + |
| 101 | + <pre class="lang-css"> |
| 102 | + #infinite_scroller { |
| 103 | + overscroll-behavior-y: none; |
| 104 | + } |
| 105 | + </pre> |
| 106 | + |
| 107 | +In this case the the author can use <a value for=overscroll-behavior>none</a> on the infinite |
| 108 | +scroller to prevent both scroll chaining and overscroll affordance. |
| 109 | +</div> |
| 110 | + |
| 111 | +Scroll chaining and boundary default actions {#scroll-chaining-and-boundary-default-actions} |
| 112 | +========================== |
| 113 | + |
| 114 | +<em>Operating Systems have rules for scrolling such as scroll chaining and overscroll affordances. |
| 115 | +This specification does not mandate if and how scroll chaining or overscroll affordances be |
| 116 | +implemented. This specification only allows the content author to disable them if any are |
| 117 | +implemented.</em> |
| 118 | + |
| 119 | +<dfn>Scroll chaining</dfn> is when scrolling is propagated from one <a>scroll container</a> to an |
| 120 | +ancestor <a>scroll container</a> following the <a>scroll chain</a>. Typically scroll chaining is |
| 121 | +performed starting at the event target recursing up the <a>containing block chain</a>. When a |
| 122 | +<a>scroll container</a> in this chain receives a scroll event or gesture it may act on it and/or |
| 123 | +pass it up the chain. Chaining typically occurs when the <a>scrollport</a> has reached its boundary. |
| 124 | + |
| 125 | +A <dfn>scroll chain</dfn> is the order in which scrolling is propagated from one <a>scroll |
| 126 | +container</a> to another. |
| 127 | + |
| 128 | +<dfn>Scroll boundary</dfn> refers to when the scroll position of a <a>scroll container</a> reaches |
| 129 | +the edge of the <a>scrollport</a>. If a scroll container has no potential to scroll, because it does |
| 130 | +not <a>overflow</a> in the direction of the scroll, the element is always considered to be at the |
| 131 | +scroll boundary. |
| 132 | + |
| 133 | +<dfn>Boundary default action</dfn> refers to the user-agent-defined <a>default action</a> performed |
| 134 | +when scrolling against the edge of the <a>scrollport</a>. A <dfn>local boundary default action</dfn> |
| 135 | +is a <a>boundary default action</a> which is performed on the <a>scroll container</a> without |
| 136 | +interacting with the page, for example displaying a overscroll UI affordance. Conversely, a <dfn |
| 137 | +>non-local boundary default action</dfn> interacts with the page, for example scroll chaining or a |
| 138 | +navigation action. |
| 139 | + |
| 140 | +Overview {#overview} |
| 141 | +========================== |
| 142 | + |
| 143 | +This module introduces control over the behavior of a <a>scroll container</a> element when its |
| 144 | +<a>scrollport</a> reaches the boundary of its scroll box. It allows the content author to specify |
| 145 | +that a <a>scroll container</a> element must prevent scroll chaining and/or overscroll affordances. |
| 146 | + |
| 147 | +Overscroll Behavior Properties {#overscroll-behavior-properties} |
| 148 | +========================== |
| 149 | + |
| 150 | +These properties specify how a <a>scroll container</a> element must behave when scrolling. A element |
| 151 | +that is not <a>scroll container</a> must accept but ignore the values of this property. This |
| 152 | +property must be applied to all input methods supported by the user agent. |
| 153 | + |
| 154 | +Note: This property should provide guarantees that are, at least, as strong as <a>preventDefault</a> |
| 155 | +for preventing both scroll chaining and overscroll. Doing otherwise would cause content authors to |
| 156 | +use <a>preventDefault</a> instead. |
| 157 | + |
| 158 | +<pre class=propdef> |
| 159 | +Name: overscroll-behavior-x, overscroll-behavior-y |
| 160 | +Value: contain | none | auto |
| 161 | +Initial: auto |
| 162 | +Applies to: <a>scroll container</a> elements |
| 163 | +Inherited: no |
| 164 | +Percentages: N/A |
| 165 | +Media: visual |
| 166 | +Computed value: as specified |
| 167 | +Animatable: no |
| 168 | +Canonical order: <abbr title="follows order of property value definition">per grammar</abbr> |
| 169 | +</pre> |
| 170 | + |
| 171 | +The 'overscroll-behavior-x' property specifies the behavior of the 'overscroll-behavior' |
| 172 | +in the horizontal direction and the 'overscroll-behavior-y' property specifies the handling of |
| 173 | +the 'overscroll-behavior' in the vertical direction. When scrolling is performed along both the |
| 174 | +horizontal and vertical axes at the same time, the 'overscroll-behavior' of each respective |
| 175 | +axis should be considered independently. |
| 176 | + |
| 177 | +<pre class=propdef> |
| 178 | +Name: overscroll-behavior |
| 179 | +Value: [ contain | none | auto ]{1,2} |
| 180 | +Initial: auto auto |
| 181 | +Applies to: <a>scroll container</a> elements |
| 182 | +Inherited: no |
| 183 | +Media: visual |
| 184 | +Computed value: see individual properties |
| 185 | +Animatable: no |
| 186 | +Canonical order: <abbr title="follows order of property value definition">per grammar</abbr> |
| 187 | +</pre> |
| 188 | + |
| 189 | +The two values specify the behavior in the horizontal and vertical direction, respectively. If only one value is specified, the second value defaults to the same value. |
| 190 | + |
| 191 | +Values have the following meanings: |
| 192 | + |
| 193 | +<dl dfn-for="overscroll-behavior, overscroll-behavior-x, overscroll-behavior-y" dfn-type="value"> |
| 194 | + <dt><dfn>contain</dfn> |
| 195 | + <dd> |
| 196 | + This value indicates that the element must not perform <a>non-local boundary default actions</a> |
| 197 | + such as scroll chaining or navigation. The user agent must not perform scroll chaining to any |
| 198 | + ancestors along the <a>scroll chain</a> regardless of whether the scroll originated at this |
| 199 | + element or one of its descendants. This value must not modify the behavior of how <a>local |
| 200 | + boundary default actions</a> should behave, such as overscroll behavior. |
| 201 | + <dt><dfn>none</dfn> |
| 202 | + <dd> |
| 203 | + This value implies the same behavior as <a value for=overscroll-behavior>contain</a> and in |
| 204 | + addition this element must also not perform <a>local boundary default actions</a> such as |
| 205 | + showing any overscroll affordances. |
| 206 | + <dt><dfn>auto</dfn> |
| 207 | + <dd> |
| 208 | + This value indicates that the user agent should perform the usual <a>boundary default action</a> |
| 209 | + with respect to <a>scroll chaining</a>, overscroll and navigation gestures. |
| 210 | +</dl> |
| 211 | + |
| 212 | +Note: In the case where a user agent does not implement scroll chaining and overscroll affordances, |
| 213 | +these values will have no side effects for a compliant implementation. |
| 214 | + |
| 215 | +Note: Programmatic scrolling is clamped and can not trigger any <a>boundary default actions</a>. |
| 216 | + |
| 217 | + |
| 218 | + |
| 219 | +Security and Privacy Considerations {#security-and-privacy} |
| 220 | +=================================== |
| 221 | +There are no known security or privacy impacts of this feature. The feature may be used to prevent |
| 222 | +certain native UI features such as overscroll affordances and overscroll navigations (e.g., pull- |
| 223 | +to-refresh, swipe navigations). However, this does not expose any additional abilities beyond what |
| 224 | +is already possible in the platform e.g., by preventing the default action of the event that would |
| 225 | +cause a scroll. |
| 226 | + |
| 227 | + |
0 commit comments