This repository has been archived by the owner on Jun 25, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tombstone the spec and point everything to the CSSWG draft.
- Loading branch information
Showing
3 changed files
with
8 additions
and
345 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,346 +1,7 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Scroll Anchoring</title> | ||
<meta charset='utf-8'> | ||
<script src='https://www.w3.org/Tools/respec/respec-w3c-common' | ||
async class='remove'></script> | ||
<script class='remove'> | ||
var respecConfig = { | ||
specStatus: "CG-DRAFT", | ||
shortName: "scrollAnchoring", | ||
edDraftURI: "https://wicg.github.io/ScrollAnchoring", | ||
editors: [ | ||
{ name: "Steve Kobes", | ||
url: "", | ||
company: "Google", | ||
companyURL: "https://www.google.com/" }, | ||
{ name: "Tab Atkins", | ||
url: "", | ||
company: "Google", | ||
companyURL: "https://www.google.com/" }, | ||
], | ||
otherLinks: [{ | ||
key: 'Participation', | ||
data: [ | ||
{ | ||
value: 'GitHub repository', | ||
href: 'https://github.com/WICG/ScrollAnchoring' | ||
}, { | ||
value: 'File a bug / view open issues', | ||
href: 'https://github.com/WICG/ScrollAnchoring/issues' | ||
}, { | ||
value: 'Feedback / discussion in the WICG', | ||
href: 'https://discourse.wicg.io/t/proposal-scroll-anchoring/1752' | ||
} | ||
] | ||
}], | ||
}; | ||
</script> | ||
</head> | ||
<body> | ||
<section id='abstract'> | ||
<p> | ||
Changes in DOM elements above the visible region of a | ||
<a href="https://drafts.csswg.org/cssom-view/#scrolling-box">scrolling box</a> | ||
can result in the page moving while the user is in the middle of consuming the content. | ||
</p> | ||
<p> | ||
This spec proposes a mechanism to mitigate this jarring user experience by | ||
keeping track of the position of an anchor node and adjusting the scroll | ||
offset accordingly. | ||
</p> | ||
<p> | ||
This spec also proposes an API for web developers to opt-out of this behavior. | ||
</p> | ||
</section> | ||
<title>Scroll Anchoring</title> | ||
<meta charset=utf-8> | ||
<h1>Scroll Anchoring Has Migrated to the CSSWG</h1> | ||
|
||
<section id='sotd'> | ||
<p> | ||
Standardizing this proposal is tracked by <a href="https://github.com/wicg/interventions/issues/2">a WICG interventions issue</a>. | ||
</p> | ||
</section> | ||
|
||
<section id="intro" class="informative"> | ||
<h2>Introduction</h2> | ||
<p> | ||
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. | ||
</p> | ||
<p> | ||
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. | ||
</p> | ||
<p> | ||
Scroll anchoring aims to minimize surprising content shifts. It does this by | ||
adjusting the scroll position to compensate for the changes outside the | ||
viewport. | ||
</p> | ||
<p> | ||
The <a href="https://github.com/WICG/ScrollAnchoring/blob/master/explainer.md">explainer | ||
document</a> gives an informal overview of scroll anchoring. | ||
</p> | ||
</section> | ||
<section dfn-for="ScrollAnchoring"> | ||
<h2>Description</h2> | ||
<p> | ||
Scroll anchoring works by selecting a DOM node (the <dfn>anchor node</dfn>) whose | ||
movement is used to determine adjustments to the scroll position. | ||
</p> | ||
<section> | ||
<h3>Anchor Node Selection</h3> | ||
<p> | ||
Each <a href="https://drafts.csswg.org/cssom-view/#scrolling-box">scrolling box</a> | ||
aims to select an anchor node that is deep in the DOM and close to the | ||
block start edge of its | ||
<a href="https://drafts.csswg.org/css-scroll-snap/#optimal-viewing-region">optimal viewing region</a>. | ||
</p> | ||
<div class="note"> | ||
If the user agent does not support the | ||
<a href="https://drafts.csswg.org/css-scroll-snap/#propdef-scroll-padding">scroll-padding</a> | ||
property, the optimal viewing region of the scrolling box is equivalent to its | ||
<a href="https://www.w3.org/TR/css3-box/#content">content area</a>. | ||
</div> | ||
<p> | ||
The anchor node is either a non-anonymous | ||
<a href="https://www.w3.org/TR/css3-box/#block">block box</a> | ||
or a <a href="https://www.w3.org/TR/dom/#text">text node</a>. | ||
The anchor node is always a <a href="https://www.w3.org/TR/dom/#concept-tree-descendant">descendant</a> | ||
of the <a href="https://drafts.csswg.org/cssom-view/#scrolling-box">scrolling box</a>. | ||
In some cases, a scrolling box may not select any anchor node. | ||
</p> | ||
<p> | ||
The <dfn id="anchoring-algorithm">anchor node selection algorithm</dfn> for a scrolling box S | ||
is as follows: | ||
<ol> | ||
<li> | ||
If S is associated with an element whose computed value of the | ||
<a href="#overflow-anchor">overflow-anchor</a> property is | ||
<a href="#overflow-anchor-none">none</a>, then do not select an anchor node for S. | ||
</li> | ||
<li> | ||
Otherwise, for each DOM child N of the element or document associated with S, perform | ||
the <a href="#candidate-examination">candidate examination algorithm</a> for N in S, | ||
and terminate if it selects an anchor node. | ||
</li> | ||
</ol> | ||
The <dfn id="candidate-examination">candidate examination algorithm</dfn> for a candidate | ||
DOM node N in a scrolling box S is as follows: | ||
<ol> | ||
<li> | ||
If N is an <a>excluded subtree</a>, or if N is <a id="ref-for-fully-clipped-1">fully | ||
clipped</a> in S, then do nothing (N and its descendants are skipped). | ||
</li> | ||
<li> | ||
If N is <a id="ref-for-fully-visible-1">fully visible</a> in S, select N as the anchor node. | ||
</li> | ||
<li> | ||
If N is <a id="ref-for-partially-visible-1">partially visible</a>: | ||
<ol type="a"> | ||
<li> | ||
For each DOM child C of N, perform the <a href="#candidate-examination">candidate | ||
examination algorithm</a> for C in S, and terminate if it selects an anchor node. | ||
</li> | ||
<li> | ||
For each <a href="https://drafts.csswg.org/css-position-3/#valdef-position-absolute">absolute-positioned</a> element A whose <a href="https://drafts.csswg.org/css-display-3/#containing-block">containing block</a> is N, but whose | ||
DOM parent is not N, perform the <a href="#candidate-examination">candidate | ||
examination algorithm</a> for A in S, and terminate if it selects an anchor node. | ||
</li> | ||
<li> | ||
Select N as the anchor node. (If this step is reached, no suitable anchor node was | ||
found among N's descendants.) | ||
</li> | ||
</ol> | ||
<div class="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> | ||
</li> | ||
</ol> | ||
</p> | ||
<p> | ||
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.) | ||
</p> | ||
<p> | ||
A DOM node N is an <dfn id="excluded-subtree">excluded subtree</dfn> if it is an element and any of the following conditions | ||
holds: | ||
<ul> | ||
<li> | ||
N's computed value of the <a href="https://www.w3.org/TR/css-display-3/#propdef-display">display</a> property is <a href="https://www.w3.org/TR/css-display-3/#valdef-display-none">none</a>. | ||
</li> | ||
<li> | ||
N's computed value of the <a href="https://drafts.csswg.org/css-position-3/#propdef-position">position</a> property is <a href="https://drafts.csswg.org/css-position-3/#valdef-position-fixed">fixed</a>. | ||
</li> | ||
<li> | ||
N's computed value of the <a href="https://drafts.csswg.org/css-position-3/#propdef-position">position</a> property is <a href="https://drafts.csswg.org/css-position-3/#valdef-position-absolute">absolute</a> and N's | ||
<a href="https://drafts.csswg.org/css-display-3/#containing-block">containing block</a> | ||
is an ancestor of the scrolling box. | ||
</li> | ||
<li> | ||
N's computed value of the <a href="#overflow-anchor">overflow-anchor</a> | ||
property is <a href="#overflow-anchor-none">none</a>. | ||
</li> | ||
</ul> | ||
</p> | ||
<p> | ||
A DOM node N is <dfn id="fully-visible">fully visible</dfn> in a scrolling box S if its | ||
<a>scroll anchoring bounding rect</a> is entirely within the | ||
<a href="https://drafts.csswg.org/css-scroll-snap/#optimal-viewing-region">optimal viewing region</a> | ||
of S. | ||
</p> | ||
<p> | ||
A DOM node N is <dfn id="fully-clipped">fully clipped</dfn> in a scrolling box S if its | ||
<a>scroll anchoring bounding rect</a> is entirely outside the | ||
<a href="https://drafts.csswg.org/css-scroll-snap/#optimal-viewing-region">optimal viewing region</a> | ||
of S. | ||
</p> | ||
<p> | ||
A DOM node N is <dfn id="partially-visible">partially visible</dfn> in a scrolling box S if it | ||
is neither fully visible in S nor fully clipped in S. | ||
</p> | ||
<p> | ||
The <dfn id="scroll-anchoring-bounding-rect">scroll anchoring bounding rect</dfn> of a DOM node N | ||
is its <a href="https://www.w3.org/TR/css-overflow-3/#scrollable-overflow-rectangle">scrollable overflow rectangle</a> | ||
if N is a <a href="https://www.w3.org/TR/css3-box/#block">block box</a>, or the bounding rect of its | ||
<a href="https://www.w3.org/TR/css-text-3/#line-breaking">line boxes</a> if N is a text node. | ||
</p> | ||
</section> | ||
<section> | ||
<h3>Scroll Adjustment</h3> | ||
<p> | ||
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 href="https://www.w3.org/TR/css-writing-modes-3/#block-flow-direction">block | ||
flow direction</a> of the scroller. | ||
</p> | ||
<p> | ||
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>. | ||
</p> | ||
<p> | ||
The scroll adjustment is a type of | ||
<a href="https://www.w3.org/TR/cssom-view-1/#scrolling-events">scrolling</a> as defined by | ||
CSSOM View Module, and generates | ||
<a href="https://www.w3.org/TR/cssom-view-1/#eventdef-document-scroll">scroll events</a> | ||
in the manner described there. | ||
</p> | ||
<h4>Suppression Window</h4> | ||
<p> | ||
Every movement of an anchor node occurs within a window of time called the | ||
<dfn id="suppression-window">suppression window</dfn>, defined as follows: | ||
<ul> | ||
<li>The suppression window begins at the start of the current iteration of the | ||
<a data-link-type="dfn" 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.</li> | ||
<li>The suppression window ends at the end of the current iteration of the | ||
<a data-link-type="dfn" 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 | ||
<a href="https://www.w3.org/TR/cssom-view-1/#dom-element-getboundingclientrect">getBoundingClientRect</a>), whichever comes sooner. | ||
</li> | ||
</ul> | ||
<div class="note"> | ||
The suppression window boundaries should be incorporated into the HTML standard once the | ||
scroll anchoring API is stabilized. | ||
</div> | ||
More than one anchor node movement may occur within the same suppression window. | ||
</p> | ||
<p> | ||
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. | ||
</p> | ||
<h4>Suppression Triggers</h4> | ||
<p> | ||
A <dfn id="suppression-trigger">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: | ||
<ul> | ||
<li> | ||
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: | ||
<ul> | ||
<li><a href="https://drafts.csswg.org/css21/visuren.html#position-props">box offset properties</a></li> | ||
<li><a href="https://drafts.csswg.org/css21/box.html#margin-properties">margin properties</a></li> | ||
<li><a href="https://drafts.csswg.org/css21/box.html#padding-properties">padding properties</a></li> | ||
<li><a href="https://drafts.csswg.org/css21/visudet.html#propdef-width">width</a>, | ||
<a href="https://drafts.csswg.org/css21/visudet.html#propdef-height">height</a>, | ||
<a href="https://drafts.csswg.org/css21/visudet.html#min-max-widths">min-width and max-width</a>, | ||
<a href="https://drafts.csswg.org/css21/visudet.html#min-max-heights">min-height and max-height</a></li> | ||
<li><a href="https://drafts.csswg.org/css-position-3/#propdef-position">position</a></li> | ||
<li><a href="https://drafts.csswg.org/css-transforms-1/#propdef-transform">transform</a></li> | ||
</ul> | ||
</li> | ||
<li> | ||
Any change to the computed value of the | ||
<a href="https://drafts.csswg.org/css-position-3/#propdef-position">position</a> | ||
property on any element within the scrollable element (or document), such that | ||
the element acquires or ceases to have an out-of-flow position | ||
(<a href="https://drafts.csswg.org/css-position-3/#fixed-pos">fixed</a> or | ||
<a href="https://drafts.csswg.org/css-position-3/#abs-pos">absolute</a>). | ||
Note that this trigger applies regardless of whether the modified element is | ||
on the path from the anchor node to the scrollable element. | ||
</li> | ||
</ul> | ||
</p> | ||
<div class="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. | ||
</div> | ||
</section> | ||
</section> | ||
<section> | ||
<h2>Exclusion API</h2> | ||
<p> | ||
Scroll anchoring aims to be the default mode of behavior when launched, so that | ||
users benefit from it even on legacy content. A CSS property | ||
<dfn id="overflow-anchor"><code>overflow-anchor</code></dfn> 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. | ||
This property supports the following values when applied to an element E: | ||
</p> | ||
<ul> | ||
<li> | ||
<dfn><code>overflow-anchor: auto</code></dfn> (the default value) declares | ||
that the DOM subtree rooted at E is eligible to participate in the | ||
<a href="#anchoring-algorithm" id="ref-for-anchoring-algorithm-1">anchor | ||
node selection algorithm</a> for any scrolling box created by E or an ancestor of E. | ||
</li> | ||
<li> | ||
<dfn id="overflow-anchor-none"><code>overflow-anchor: none</code></dfn> | ||
declares that the DOM subtree rooted at E is <em>not</em> eligible to | ||
participate in the <a href="#anchoring-algorithm" | ||
id="ref-for-anchoring-algorithm-1">anchor node selection algorithm</a> | ||
for any scrolling box created by E or an ancestor of E. | ||
</li> | ||
</ul> | ||
<div class="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>. | ||
</div> | ||
<p> | ||
The <code>overflow-anchor</code> property is not inherited. | ||
</p> | ||
</section> | ||
|
||
<h2 id="references">References</h2> | ||
<h3 id="normative">Normative References</h3> | ||
<dl> | ||
<dt id="biblio-cssom-view-1">[CSSOM-VIEW-1] | ||
<dd>Simon Pieters. <a href="https://drafts.csswg.org/cssom-view/">CSSOM View Module</a>. 17 March 2016. WD. URL: <a href="https://drafts.csswg.org/cssom-view/">https://drafts.csswg.org/cssom-view/</a> | ||
</dl> | ||
</body> | ||
</html> | ||
<p>The Scroll Anchoring spec has graduated from the WICG, | ||
and is now <a href="https://drafts.csswg.org/css-scroll-anchoring>a CSSWG spec</a>. |