-
Notifications
You must be signed in to change notification settings - Fork 656
/
Overview.bs
345 lines (282 loc) · 14.1 KB
/
Overview.bs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
<pre class=metadata>
Title: CSS Scroll Anchoring Module Level 1
Shortname: css-scroll-anchoring
Level: 1
Group: csswg
Status: ED
Work Status: Revising
ED: https://drafts.csswg.org/css-scroll-anchoring/
TR: https://www.w3.org/TR/css-scroll-anchoring-1/
Previous Version: https://www.w3.org/TR/2020/WD-css-scroll-anchoring-1-20200211/
Editor: Steve Kobes, Google
Editor: Tab Atkins-Bittner, Google, http://xanthir.com/contact/, w3cid 42199
Abstract: Changes in DOM elements above the visible region of a <a>scrolling box</a> can result in the page moving
Abstract: while the user is in the middle of consuming the content.
Abstract:
Abstract: This spec proposes a mechanism to mitigate this jarring user experience
Abstract: by keeping track of the position of an anchor node and adjusting the scroll offset accordingly.
Abstract:
Abstract: This spec also proposes an API for web developers to opt-out of this behavior.
</pre>
<pre class=link-defaults>
spec:css-box; type:dfn; text:content area
spec:css2;
type:dfn; text:line box
spec:css-sizing-3;
type:property;
text:max-height
text:min-height
text:height
text:max-width
text:min-width
text:width
</pre>
<pre class="anchors">
spec: html; urlPrefix: https://html.spec.whatwg.org/multipage/;
urlPrefix: interaction.html
type: dfn;
text:DOM anchor
text:focused area of the document
text:active match; url: fip-active-match
urlPrefix: form-control-infrastructure.html
type: dfn;
text:mutable; url: concept-fe-mutable
spec: html; urlPrefix: https://w3c.github.io/editing/docs/execCommand/;
urlPrefix: index.html
type: dfn;
text:editable
</pre>
<h2 id=intro>
Introduction</h2>
Today, users of the web are often distracted by content moving around
due to changes that occur outside the viewport.
Examples include script inserting an iframe containing an ad,
or non-sized images loading on a slow network.
Historically the browser's default behavior has been
to preserve the absolute scroll position when such changes occur.
This means that to avoid shifting content,
the webpage can attempt to reserve space on the page
for anything that will load later.
In practice, few websites do this consistently.
Scroll anchoring aims to minimize surprising content shifts.
It does this by adjusting the scroll position
to compensate for the changes outside the viewport.
The <a href="https://github.com/WICG/ScrollAnchoring/blob/master/explainer.md">explainer document</a>
gives an informal overview of scroll anchoring.
<h3 id="values">
Value Definitions</h3>
This specification follows the <a href="https://www.w3.org/TR/CSS2/about.html#property-defs">CSS property definition conventions</a> from [[!CSS2]]
using the <a href="https://www.w3.org/TR/css-values-3/#value-defs">value definition syntax</a> from [[!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 the <a>CSS-wide keywords</a> as their property value.
For readability they have not been repeated explicitly.
<h2 id='description'>
Description</h2>
Scroll anchoring attempts to keep the user's view of the document stable across layout changes.
It works by selecting a DOM node (the <dfn export for=scroll-anchoring>anchor node</dfn>)
whose movement is used to determine adjustments to the scroll position.
However, if the scroll container is currently [=scroll snap|snapped=] to an element,
(see [[!CSS-SCROLL-SNAP-1]])
scroll anchoring is limited to adjustments that would be allowed by [=re-snapping=].
<h3 id='anchor-node-selection'>
Anchor Node Selection</h3>
Each <a>scrolling box</a> aims to select an <a>anchor node</a>
that is deep in the DOM
and either should be prioritized as an important DOM node or is close to the
block start edge of its <a>optimal viewing region</a>.
Note: If the user agent does not support the 'scroll-padding' property,
the optimal viewing region of the scrolling box is equivalent to its <a>content area</a>.
An anchor node can be any <a>box</a> except one for a non-<a>atomic inline</a>.
The anchor node is always a <a>descendant</a> of the <a>scrolling box</a>.
In some cases, a scrolling box may not select any anchor node.
An element |C| is a <dfn id="anchor-viable-candidate">viable candidate</dfn>
for becoming a scroll anchor for a scrolling box |S| if it meets all of the
following criteria:
* |C| is an element that is not a non-<a>atomic inline</a>.
* |C| is <a>partially visible</a> or <a>fully visible</a> in |S|
* |C| is a descendant of |S|
* |C| is not in an <a>excluded subtree</a>
* None of the ancestors of |C| up to |S| are in an <a>excluded subtree</a>
Some elements are considered to be <dfn
id="anchor-priority-candidates">priority candidates</dfn> for anchor selection:
1. The [=DOM anchor=] of the [=focused area of the document=], if such an anchor
is text editable ([=editable=], [=editing host=], [=mutable=] <{textarea}>, or
[=mutable=] <{input}> with a type that allows text entry).
2. An element containing the current [=active match=] of the
find-in-page user-agent algorithm. If the match spans multiple elements, then
consider only the first such element.
Note that if the <a>priority candidate</a> is a non-<a>atomic inline</a>
element, then instead consider its nearest ancestor element that is not a
non-atomic inline element as the priority candidate.
<div algorithm>
The <dfn id="anchoring-algorithm">anchor node selection algorithm</dfn>
for a scrolling box |S| is as follows:
1. If |S| is associated with an element
whose computed value of the 'overflow-anchor' property is ''overflow-anchor/none'',
then do not select an anchor node for |S|.
2. Otherwise, for each <a>priority candidate</a> |PC| in order specified,
check if |PC| is a <a>viable candidate</a> in |S|. If so, select it as an
anchor node and terminate.
3. Otherwise, for each DOM child |N| of the element or document associated with |S|,
perform the <a>candidate examination algorithm</a> for |N| in |S|,
and terminate if it selects an anchor node.
</div>
<div algorithm>
The <dfn id="candidate-examination">candidate examination algorithm</dfn>
for a candidate DOM node |N| in a scrolling box |S| is as follows:
1. If |N| is an <a>excluded subtree</a>,
or if |N| is <a>fully clipped</a> in |S|,
then do nothing (|N| and its descendants are skipped).
2. If |N| is <a>fully visible</a> in |S|,
select |N| as the anchor node.
3. If N is <a>partially visible</a>:
1. For each DOM child |C| of |N|,
perform the <a>candidate examination algorithm</a> for |C| in |S|,
and terminate if it selects an anchor node.
2. For each absolutely-positioned element |A|
whose <a>containing block</a> is |N|,
but whose DOM parent is not |N|,
perform the <a>candidate examination algorithm</a> for |A| in |S|,
and terminate if it selects an anchor node.
3. Select |N| as the anchor node.
(If this step is reached,
no suitable anchor node was found among |N|’s descendants.)
Note: Deeper nodes are preferred to minimize the possibility of content changing
inside the anchor node but outside the viewport, which would cause visible
content to shift without triggering any scroll anchoring adjustment.
</div>
Conceptually, a new anchor node is computed for every scrolling box
whenever the scroll position of any scrolling box changes.
(As a performance optimization,
the implementation may wait until the anchor node is needed before computing it.)
<div algorithm>
A DOM node |N| is an <dfn>excluded subtree</dfn>
if it is an element and any of the following conditions holds:
* |N|’s computed value of the 'display' property is ''display/none''.
* |N|’s computed value of the 'position' property is ''position/fixed''.
* |N|’s computed value of the 'position' property is ''position/absolute''
and |N|’s <a>containing block</a> is an ancestor of the scrolling box.
* |N|’s computed value of the 'overflow-anchor' property is ''overflow-anchor/none''.
</div>
<div algorithm>
A DOM node |N| is <dfn>fully visible</dfn> in a scrolling box |S|
if |N|’s <a>scroll anchoring bounding rect</a> is entirely within the <a>optimal viewing region</a> of |S|.
</div>
<div algorithm>
A DOM node |N| is <dfn>fully clipped</dfn> in a scrolling box |S|
if |N|’s <a>scroll anchoring bounding rect</a> is entirely outside the <a>optimal viewing region</a> of |S|.
</div>
<div algorithm>
A DOM node |N| is <dfn>partially visible</dfn> in a scrolling box |S|
if |N| is neither <a>fully visible</a> in |S| nor <a>fully clipped</a> in |S|.
</div>
<div algorithm>
The <dfn>scroll anchoring bounding rect</dfn> of a DOM node |N|
is |N|’s <a>scrollable overflow rectangle</a>.
</div>
<h3 id="scroll-adjustment">
Scroll Adjustment</h3>
If an anchor node was selected,
then when the anchor node moves,
the browser computes the previous offset <code>y0</code>, and the current offset <code>y1</code>,
of the block start edge of the anchor node's <a>scroll anchoring bounding rect</a>,
relative to the block start edge of the scrolling content in the <a>block flow direction</a> of the scroller.
It then queues an adjustment to the scroll position of <code>y1 - y0</code>,
in the block flow direction,
to be performed at the end of the <a>suppression window</a>.
The scroll adjustment is a type of [[cssom-view-1#scrolling-events#scrolling]] as defined by [[!CSSOM-VIEW]],
and generates <a event lt=scroll>scroll events</a> in the manner described there.
<h4 id="suppression-windows">
Suppression Window</h4>
Every movement of an anchor node occurs within a window of time
called the <dfn>suppression window</dfn>,
defined as follows:
* The suppression window begins at the start of the current iteration of the
<a href="https://html.spec.whatwg.org/multipage/webappapis.html#processing-model-8">HTML Processing Model</a> event loop,
or at the end of the most recently completed suppression window,
whichever is more recent.
* The suppression window ends at the end of the current iteration of the
<a href="https://html.spec.whatwg.org/multipage/webappapis.html#processing-model-8">HTML Processing Model</a> event loop,
or immediately before the next operation whose result or side effects
would differ as a result of a change in the scroll position
(for example, an invocation of {{Element/getBoundingClientRect()}}),
whichever comes sooner.
Note: The suppression window boundaries should be incorporated into the HTML standard once the
scroll anchoring API is stabilized.
More than one anchor node movement may occur within the same suppression window.
At the end of a suppression window,
the user agent performs all scroll adjustments that were queued during the window
and not suppressed by any <a>suppression trigger</a> during the window.
<h4 id="suppression-triggers">
Suppression Triggers</h4>
A <dfn>suppression trigger</dfn> is an operation
that suppresses the scroll anchoring adjustment for an anchor node movement,
if it occurs within the suppression window for that movement.
These triggers are:
* Any change to the computed value of any of the following properties,
on any element in the path from the anchor node to the scrollable element (or document),
inclusive of both:
* 'top', 'left', 'right', or 'bottom'
* 'margin' or its longhands
* 'padding' or its longhands
* 'width', 'height', 'min-width', 'max-width', 'min-height', or 'max-height'
* 'position'
* 'transform'
* Any change to the computed value of the 'position' property
on any element within the scrollable element (or document),
such that the element becomes or stops being absolutely positioned.
Note that this trigger applies regardless of whether the modified element is
on the path from the anchor node to the scrollable element.
* The scroll offset of the scrollable element being zero.
Note: Suppression triggers exist for compatibility with existing web content that has negative
interactions with scroll anchoring due to shifting content in scroll event handlers.
<h2 id="exclusion-api">
Exclusion API</h2>
Scroll anchoring aims to be the default mode of behavior when launched,
so that users benefit from it even on legacy content.
'overflow-anchor' can disable scroll anchoring in part or all of a webpage (opt out),
or exclude portions of the DOM from the anchor node selection algorithm.
<pre class=propdef>
Name: overflow-anchor
Value: auto | none
Initial: auto
Inherited: no
Computed value: specified keyword
Animation type: discrete
</pre>
Values are defined as follows:
<dl dfn-type=value dfn-for=overflow-anchor>
: <dfn>auto</dfn>
::
Declares that the element
is potentially eligible to participate in the <a>anchor node selection algorithm</a>
for any scrolling box created by the element or an ancestor.
: <dfn>none</dfn>
::
Declares that the element and its descendants
(that aren't nested inside of another scrolling element)
are <em>not</em> eligible to participate in the <a>anchor node selection algorithm</a>
for any scrolling box created by the element or an ancestor.
</dl>
Note: It is not possible to turn scroll anchoring "back on"
for descendants of a ''overflow-anchor: none'' element.
However, descendant <a>scroll containers</a> automatically "turn it back on"
(for their own scrolling box)
unless they explicitly have ''overflow-anchor: none'' set on them as well.
Note: The <code>overflow-anchor</code> property was also proposed (with different values)
for <a href="http://tabatkins.github.io/specs/css-sticky-scrollbars/">CSS Sticky Scrollbars</a>,
which has now been <a href="https://tabatkins.github.io/specs/css-sticky-scrollbars/#intro">superseded</a>.
<h2 id='priv-sec'>
Privacy and Security Considerations</h2>
This specification,
as it only adjusts how we compute scroll positions,
introduces no new privacy or security considerations.
<h2 id='changes' class="no-num">
Changes</h2>
<h3 id='changes-20200211'>
Changes Since the Feb 11 2020 Working Draft</h3>
* Added definitions of [=viable candidate=] and [=priority candidate=].
* Clarified interaction between scroll anchoring and [=scroll snapping=].