Group: csswg Shortname: css-snappoints Level: 1 Status: ED ED: http://dev.w3.org/csswg/css-snappoints/ Editor: Matt Rakow, Microsoft Editor: Jacob Rossi, Microsoft Abstract: This module contains features to control panning and scrolling behavior with "snap points". !Issue Tracking: http://wiki.csswg.org/spec/css-snappoints Ignored Terms: scroll-snap-points-*
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>
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>
.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>
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: no
Name: scroll-snap-points-x, scroll-snap-points-y
Value: none | repeat(<>)
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: no
Name: scroll-snap-destination
Value: <>
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: yes
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 | <>#
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: yes
How can an alternative box be specified?