Skip to content

Commit d77997a

Browse files
committed
[css-scroll-snap] Add “Choosing Snap Positions” section.
1 parent 8e81c41 commit d77997a

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

css-scroll-snap/Overview.bs

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,24 @@ Scroll Snap Limits: the 'scroll-snap-stop' property {#scroll-snap-stop}
649649

650650
Issue: It's been proposed to rename ''normal'', but not to what.
651651

652+
Snapping Mechanics {#snap-concepts}
653+
===================================
654+
655+
The precise model algorithm to select a <a>snap position</a> to snap to
656+
is intentionally left mostly undefined,
657+
so that user agents can take into account sophisticated models of user intention and interaction
658+
and adjust how they respond over time,
659+
to best serve the user.
660+
661+
This section defines some useful concepts to aid in discussing scroll-snapping mechanics,
662+
and provides some guidelines for what an effective scroll-snapping strategy might look like.
663+
User agents are encouraged to adapt this guidance
664+
and apply their own best judgement
665+
when defining their own snapping behavior.
666+
It also provides a small number of behavior requirements,
667+
to ensure a minimum reasonable behavior that authors can depend on
668+
when designing their interfaces with scroll-snapping in mind.
669+
652670
<!--
653671
██ ████████ ███████ ████████
654672
████ ██ ██ ██ ██ ██ ██
@@ -704,6 +722,76 @@ Axis vs Point-Snapping {#snap-dimensions}
704722
while the vertical was aligned to a different element
705723
(which is the behavior you'd get if the <a>scroll container</a> was <a>axis-snapping</a>).
706724

725+
<!--
726+
██████ ██ ██ ███████ ███████ ██████ ████ ██ ██ ██████
727+
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ███ ██ ██ ██
728+
██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ██ ██
729+
██ █████████ ██ ██ ██ ██ ██████ ██ ██ ██ ██ ██ ████
730+
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ██ ██
731+
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ███ ██ ██
732+
██████ ██ ██ ███████ ███████ ██████ ████ ██ ██ ██████
733+
-->
734+
735+
Choosing Snap Positions {#choosing}
736+
-----------------------------------
737+
738+
A <a>scroll container</a> can have many <a>snap areas</a>
739+
scattered throughout its <a>scrollable overflow region</a>.
740+
A naive algorithm for selecting a <a>snap position</a>
741+
can produce behavior that is unintuitive for users,
742+
so care is required when designing a selection algorithm.
743+
Here are a few pointers that can aid in the selection process:
744+
745+
* <a>Snap positions</a> should be chosen to minimize the distance between the end-point
746+
(or the <a>natural end-point</a>)
747+
and the final snapped scroll position,
748+
subject to the additional constraints listed in this section.
749+
750+
* <a>Point-snapping</a> is all-or-nothing;
751+
if the <a>snap position</a> of an element is chosen to align to,
752+
the <a>scroll container</a> must set its scroll position
753+
according to the element's <a>snap positions</a> in <em>both</em> axises;
754+
the <a>scroll container</a> <em>must not</em> “partially align” to the element
755+
by taking its <a>snap position</a> in one axis
756+
and aligning the other axis according to something else.
757+
758+
* If a scroll is <a>axis-locked</a> and the <a>scroll container</a> is <a>axis-snapping</a>,
759+
any <a>snap positions</a> in the other axis should be ignored
760+
during the scroll.
761+
(However, <a>snap positions</a> in the other axis can still effect the final scroll position.)
762+
763+
If a scroll is <a>axis-locked</a> and the <a>scroll container</a> is <a>point-snapping</a>,
764+
<a>snap positions</a> should be penalized in the selection process
765+
according to the amount of other-axis scrolling they would cause.
766+
767+
* <a>Snap positions</a> should be ignored if their elements are far outside of the “corridor”
768+
that the <a>snapport</a> defines as it moves through the <a>scrollable overflow region</a>
769+
during an <a>inertial scroll</a>,
770+
or a hypothetical “corridor” in the direction of a <a>directional scroll</a>,
771+
or the <a>snapport</a> after an <a>explicit scroll</a>.
772+
(This is to prevent a far-offscreen element
773+
from having difficult-to-understand effects
774+
on the scroll position.)
775+
776+
* User agents <em>must</em> ensure that a user can “escape” a <a>snap position</a>,
777+
regardless of the scroll method.
778+
For example, if the snap type is ''mandatory''
779+
and the next <a>snap position</a> is more than two screen-widths away,
780+
a naïve “always snap to nearest” selection algorithm would “trap” the user
781+
if they were panning with a touch gesture;
782+
a sufficiently large distance would even trap fling scrolling!
783+
Instead, a smarter algorithm that only returned to the starting <a>snap position</a>
784+
if the end-point was a fairly small distance from it,
785+
and otherwise ignored the starting snap position,
786+
would give better behavior.
787+
788+
(This implies that a <a>directional scroll</a> must always ignore the starting <a>snap positions</a>.)
789+
790+
* If a page is navigated to a fragment that defines a target element
791+
(one that would be matched by '':target''),
792+
and that element defines some <a>snap positions</a>,
793+
the user agent should <a>snap</a> to one of that element's <a>snap positions</a>.
794+
The user agent may do this even when the <a>scroll container</a> has ''scroll-snap-type: none''.
707795

708796
<!--
709797
██ ███████ ██ ██ ██████ ██ ██ ███ ██ ██ ████████ ██████

0 commit comments

Comments
 (0)