This module contains features to control panning and scrolling behavior with "snap points".
CSSis a language for describing the rendering of structured documents (such as HTML and XML) on screen, on paper, in speech, etc.
Status of this documentThis section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index at http://www.w3.org/TR/.
This document is a First Public Working Draft.
Publication as a First Public Working Draft does not imply endorsement by the W3C Membership. This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress.
The (archived) public mailing list www-style@w3.org (see instructions) is preferred for discussion of this specification. When sending e-mail, please put the text “css-snappoints” in the subject, preferably like this: “[css-snappoints] …summary of comment…”
This document was produced by the CSS Working Group (part of the Style Activity).
This document was produced by a group operating under the 5 February 2004 W3C Patent Policy. W3C maintains a public list of any patent disclosures made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.
This document is governed by the 1 August 2014 W3C Process Document.
Table of Contents 1. IntroductionThis section is not normative.
Popular UX paradigms for scrollable content frequently employ paging through content, or sectioning into logical divisions. This is especially true for touch interactions where it is quicker and easier for users to quickly pan through a flatly-arranged breadth of content rather than delving into a heirarchical structure through tap navigation. For example, it is easier for a user to view many photos in a photo album by panning through a photo slideshow view rather than tapping on individual photos in an album.
However, given the imprecise nature of scrolling inputs like touch panning and mousewheel scrolling, it is difficult for web developers to guarantee a well-controlled scrolling experience, in particular creating the effect of paging through content. For instance, it is easy for a user to land at an awkward scroll offset which leaves a page partially on-screen when panning.
To this end, we introduce scroll snap points which enforce the scroll offsets that a scroll container’s visual viewport may end at after a scrolling operation has completed.
1.1. Module interactionsThis module extends the scrolling user interface features defined in [CSS21] section 11.1.
None of the properties in this module apply to the ::first-line and ::first-letter pseudo-elements.
1.2. ValuesThis specification follows the CSS property definition conventions from [CSS21]. Value types not defined in this specification are defined in CSS Level 2 Revision 1 [CSS21]. Other CSS modules may expand the definitions of these value types: for example [CSS3VAL], when combined with this module, expands the definition of the <length> value type as used in this specification.
2. Motivating ExamplesIn this example, a series of images arranged in a
scroll containerare used to build a photo gallery. The
scroll containeris sized to the same size of the images contained therein. Using mandatory snap points, scrolling will always complete with a snap point aligned to the edge of the
scroll container’svisual viewport. By aligning a snap point at the edge of each image, this creates a photo viewer were users can scroll through the images one at a time.
img { width:500px; } .photoGallery { width: 500px; overflow-x: auto; overflow-y: hidden; white-space: nowrap; /* Sets up points to which scrolling will snap along x-axis */ scroll-snap-points-x: repeat(100%); /* Requires that scrolling always end at a snap point when the operation completes (hard snap) */ scroll-snap-type: mandatory; }
<div class="photoGallery"> <img src="img1.jpg"> <img src="img2.jpg"> <img src="img3.jpg"> <img src="img4.jpg"> <img src="img5.jpg"> </div>The layout of the scroll container’s contents in the example. Snap points are set along the x-axis, starting at 0px and repeating at intervals of 100% of the scroll container’s width.
This example also builds a photo gallery as in example 1. However, in this example the
scroll containeris larger than the photos contained within (such that multiple images may be seen simultaneously), and the image sizes vary (such that a repeating snap interval would not be effective). Using mandatory element-based snap points, scrolling will always complete with an image centered in the
scroll container’svisual viewport.
img { /* Defines the center of each photo as the coordinate that should be used for snapping */ scroll-snap-coordinate: 50% 50%; } .photoGallery { width: 500px; overflow-x: auto; overflow-y: hidden; white-space: nowrap; /* Specifies that each element’s snap coordinate should align with the center of the scroll container */ scroll-snap-destination: 50% 50%; /* Requires that scrolling always end at a snap point when the operation completes (hard snap). */ scroll-snap-type: mandatory; }
<div class="photoGallery"> <img src="img1.jpg"> <img src="img2.jpg"> <img src="img3.jpg"> <img src="img4.jpg"> <img src="img5.jpg"> </div>The layout of the scroll container’s contents in the example. The snap-destination is horizontally and vertically centered within the scroll container’s visual viewport (represented by a red X), and each element has its snap coordinate horizontally and vertically centered within the element (represented by yellow plus signs).
This example builds a paginated document that aligns each page near to (but not exactly on) the edge of the
scroll container. This allows the previous page to "peek" in from above in order to make the user aware that they are not yet at the top of the document. Using proximity snap points instead of mandatory snap points allows the user to stop halfway through a page (rather than forcing them to snap one page at a time). However, if a scrolling operation would finish near a snap point, then the scroll will be adjusted to align the page as specified.
.page { /* Defines the top center of each page as the coordinate that should be used for snapping */ scroll-snap-coordinate: 50% 0; } .docScroller { width: 500px; overflow-x: hidden; overflow-y: auto; /* Specifies that each element’s snap coordinate should align with the center of the scroll container, offset a short distance from the top edge. */ scroll-snap-destination: 50% 100px; /* Encourages scrolling to end at a snap point when the operation completes, if it is near a snap point */ scroll-snap-type: proximity; }
<div class="docScroller"> <div class="page">Page 1</div> <div class="page">Page 2</div> <div class="page">Page 3</div> <div class="page">Page 4</div> </div>The layout of the scroll container’s contents in the example. The snap-destination is horizontally centered and offset 100px from the top edge with respect to the scroll container’s visual viewport (represented by a red X), and each element has its snap coordinate horizontally centered and top-aligned with respect to the element (represented by yellow plus signs). 3. Definitions
The scroll-snap-type property is used to define how strictly snap points are enforced on the scroll container, if any are present. It defines how and when snap points are enforced on the visual viewport of the scroll container it is applied to in order to adjust scroll offset. It intentionally does not specify nor mandate any precise animations or physics used to enforce those snap points; this is left up to the user agent.
Name: scroll-snap-type Value: none | mandatory | proximity Initial: none Applies to: scroll containers Inherited: no Percentages: n/a Media: interactive Computed value: specified value Animatable: noDescribe the guarantee as an invariant for better clarity. Include edge case behavior such as mandatory snap points when there is no satisfiable snap point.
The scroll-snap-points-x and scroll-snap-points-y properties are used to define the positioning of snap points within the content of the scroll container they are applied to.
Name: scroll-snap-points-x, scroll-snap-points-y Value: none | repeat(<length>) Initial: none Applies to: scroll containers Inherited: no Percentages: relative to same axis of the padding-box of the scroll container Media: interactive Computed value: specified value, with lengths made absolute Animatable: noShould there be a way to specify that either end of the scrollable content should have a snap point?
The scroll-snap-destination property is used to define the x and y coordinate within the scroll container’s visual viewport which element snap points will align with.
Name: scroll-snap-destination Value: <position> Initial: 0px 0px Applies to: scroll containers Inherited: no Percentages: relative to width and height of the padding-box of the scroll container Media: interactive Computed value: specified value, with lengths made absolute Animatable: yesThe scroll-snap-coordinate property is used to define the x and y coordinate within the element which will align with the nearest ancestor scroll container’s snap-destination for the respective axis. In the case that the element has been transformed, the snap coordinate is also transformed in the same way (such that the snap-point is aligned with the element as-drawn).
How does this work with fragmentation?
Consider alternative naming besides "coordinate". Consider naming conventions like in Grid Layout for grouping properties on the container vs. items.
Name: scroll-snap-coordinate Value: none | <position># Initial: none Applies to: all elements Inherited: no Percentages: refer to the element’s border box Media: interactive Computed value: specified value, with lengths made absolute Animatable: yesHow can an alternative box be specified?
AcknowledgmentsMany thanks to lots of people for their proposals and recommendations, some of which are incorporated into this document.
Conformance Document conventionsConformance requirements are expressed with a combination of descriptive assertions and RFC 2119 terminology. The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in the normative parts of this document are to be interpreted as described in RFC 2119. However, for readability, these words do not appear in all uppercase letters in this specification.
All of the text of this specification is normative except sections explicitly marked as non-normative, examples, and notes. [RFC2119]
Examples in this specification are introduced with the words "for example" or are set apart from the normative text with class="example"
, like this:
This is an example of an informative example.
Informative notes begin with the word "Note" and are set apart from the normative text with class="note"
, like this:
Note, this is an informative note.
Advisements are normative sections styled to evoke special attention and are set apart from other normative text with <strong class="advisement">
, like this: UAs MUST provide an accessible alternative.
Conformance to this specification is defined for three conformance classes:
A style sheet is conformant to this specification if all of its statements that use syntax defined in this module are valid according to the generic CSS grammar and the individual grammars of each feature defined in this module.
A renderer is conformant to this specification if, in addition to interpreting the style sheet as defined by the appropriate specifications, it supports all the features defined by this specification by parsing them correctly and rendering the document accordingly. However, the inability of a UA to correctly render a document due to limitations of the device does not make the UA non-conformant. (For example, a UA is not required to render color on a monochrome monitor.)
An authoring tool is conformant to this specification if it writes style sheets that are syntactically correct according to the generic CSS grammar and the individual grammars of each feature in this module, and meet all other conformance requirements of style sheets as described in this module.
Partial implementationsSo that authors can exploit the forward-compatible parsing rules to assign fallback values, CSS renderers must treat as invalid (and ignore as appropriate) any at-rules, properties, property values, keywords, and other syntactic constructs for which they have no usable level of support. In particular, user agents must not selectively ignore unsupported component values and honor supported values in a single multi-value property declaration: if any value is considered invalid (as unsupported values must be), CSS requires that the entire declaration be ignored.
Experimental implementationsTo avoid clashes with future CSS features, the CSS2.1 specification reserves a prefixed syntax for proprietary and experimental extensions to CSS.
Prior to a specification reaching the Candidate Recommendation stage in the W3C process, all implementations of a CSS feature are considered experimental. The CSS Working Group recommends that implementations use a vendor-prefixed syntax for such features, including those in W3C Working Drafts. This avoids incompatibilities with future changes in the draft.
Non-experimental implementationsOnce a specification reaches the Candidate Recommendation stage, non-experimental implementations are possible, and implementors should release an unprefixed implementation of any CR-level feature they can demonstrate to be correctly implemented according to spec.
To establish and maintain the interoperability of CSS across implementations, the CSS Working Group requests that non-experimental CSS renderers submit an implementation report (and, if necessary, the testcases used for that implementation report) to the W3C before releasing an unprefixed implementation of any CSS features. Testcases submitted to W3C are subject to review and correction by the CSS Working Group.
Further information on submitting testcases and implementation reports can be found from on the CSS Working Group’s website at http://www.w3.org/Style/CSS/Test/. Questions should be directed to the public-css-testsuite@w3.org mailing list.
Index Terms defined by this specificationDescribe the guarantee as an invariant for better clarity. Include edge case behavior such as mandatory snap points when there is no satisfiable snap point.
↵Should there be a way to specify that either end of the scrollable content should have a snap point?
↵How does this work with fragmentation?
↵Consider alternative naming besides "coordinate". Consider naming conventions like in Grid Layout for grouping properties on the container vs. items.
↵How can an alternative box be specified?
↵RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4