Skip to content

Commit 0064f56

Browse files
authored
[css-scroll-snap-1] Define selection of snap area when there are multiple aligned candidates. (w3c#10057)
Implements the algorithm agreed upon in w3c#9622 to select a particular snap area in each axis.
1 parent 5410244 commit 0064f56

File tree

1 file changed

+39
-16
lines changed

1 file changed

+39
-16
lines changed

css-scroll-snap-1/Overview.bs

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,16 @@ Scroll Snap Model {#overview}
250250

251251
The act of adjusting the scroll position
252252
of a scroll container’s scrollport
253-
such that it is aligned to a snap position
253+
such that it is aligned to a snap area
254254
is called <dfn export lt="scroll snap" local-lt="snap">snapping</dfn>,
255-
and a <a>scroll container</a> is said to be
256-
<a>snapped</a> to a <a>snap position</a>
257-
if its scrollport’s scroll position
258-
is that <a>snap position</a>
255+
and a <a>scroll container</a> may be
256+
<a>snapped</a> to a <a>snap area</a>
257+
in each axis
258+
if its scrollport is aligned with that <a>snap area</a> in that axis
259259
and there is no active scrolling operation.
260+
When there are multiple valid snap areas,
261+
a single one is chosen for each axis when <a>snapping</a>
262+
according to the algorithm for <a href="#multiple-aligned-snap-areas">selecting between multiple aligned snap areas</a>.
260263
The CSS Scroll Snap Module
261264
intentionally does not specify nor mandate
262265
any precise animations or physics used to enforce <a>snap positions</a>;
@@ -417,18 +420,17 @@ Re-snapping After Layout Changes</h4>
417420
the UA must re-evaluate the resulting <a>scroll position</a>,
418421
and re-snap if required.
419422
If the <a>scroll container</a> was <a>snapped</a> before the content change
420-
and that same <a>snap position</a> still exists
421-
(e.g. its associated element was not deleted),
422-
the scroll container must be re-snapped to that same snap position
423+
and those same [=snap areas=] still exist
424+
(e.g. their associated elements were not deleted),
425+
the scroll container must be re-snapped to those same snap areas
423426
after the content change.
424-
If multiple boxes were [=snapped=] before
425-
and their [=snap positions=] no longer coincide,
426-
then if one of them is focused or targeted,
427-
the [=scroll container=] must re-snap to that one
428-
and otherwise which one to re-snap to is UA-defined.
429-
(The UA may, for example, track which element is snapped
430-
as layout shifts align and de-align
431-
the [=snap positions=] of other elements.)
427+
A <a>snap area</a> can be [=snapped=] in each axis,
428+
following the algorithm for <a href="#multiple-aligned-snap-areas">selecting between multiple aligned snap areas</a>.
429+
If it is not possible to snap to both
430+
(e.g. if snapping to one resulted in the other being offscreen),
431+
it must prefer the focused box,
432+
followed by the targeted box,
433+
followed by the block axis if neither box is focused or targeted.
432434

433435
Scrolling required by a re-snap operation to a new or different box
434436
must behave and animate the same way as
@@ -1088,6 +1090,27 @@ Choosing Snap Positions {#choosing}
10881090
if its nearest <a>scroll container</a> is a <a>scroll snap container</a>.
10891091
The user agent <em>may</em> also do this even when the <a>scroll container</a> has ''scroll-snap-type: none''.
10901092

1093+
<h4 id="multiple-aligned-snap-areas">Selecting between multiple aligned snap areas</h4>
1094+
1095+
When <a>snapping</a> to a scroll position
1096+
that is aligned with multiple [=scroll snap areas=],
1097+
the following algorithm procedure is used to determined which box is <a>snapped</a> on the block and inline axes
1098+
for a particular <a>scroll container</a>:
1099+
1100+
1. Let |scroll position| be the scroll position of the <a>scroll container</a>
1101+
1. Let |inline| be the set of boxes whose [=scroll snap areas=] are aligned at this |scroll position| in the inline axis.
1102+
1. Let |block| be the set of boxes whose [=scroll snap areas=] are aligned at this |scroll position| in the block axis.
1103+
1. For each |list| of |block| and |inline|:
1104+
1. If |list| contains the focused box, remove all other boxes from |list|.
1105+
1. If |list| contains the targeted box, remove all other boxes from |list|.
1106+
1. For each |box| in |list|:
1107+
1. Remove any box from |list| which is an ancestor of |box|.
1108+
1. If |inline| and |block| are overlapping sets:
1109+
1. Replace |inline| with the intersection of |inline| and |block|.
1110+
1. Replace |block| with the intersection of |inline| and |block|.
1111+
1. Select the first element in <a>tree order</a> from |inline| as the <a>snapped</a> inline axis box.
1112+
1. Select the first element in <a>tree order</a> from |block| as the <a>snapped</a> block axis box.
1113+
10911114
<!--
10921115
██ ███████ ██ ██ ██████ ██ ██ ███ ██ ██ ████████ ██████
10931116
██ ██ ██ ███ ██ ██ ██ ██ ██ ██ ██ ███ ██ ██ ██ ██ ██

0 commit comments

Comments
 (0)