过时
This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.
scroll-snap-destination
CSS
property defines the position in x and y coordinates within the scroll container's visual
viewport
which element snap points align with.
/* <position> value */ scroll-snap-destination: 400px 600px; /* Global values */ scroll-snap-destination: inherit; scroll-snap-destination: initial; scroll-snap-destination: unset;
<position>
Specifies the offset of the snap destination from the start edge of the scroll container’s visual viewport. The first value gives the x coordinate of the snap destination, the second value its y coordinate.
| 初始值 |
0px 0px
|
|---|---|
| 适用于 | scroll containers |
| 继承 | no |
| 百分比 | relative to same axis of the padding-box of the scroll container |
| 计算值 | as specified, but with relative lengths converted into absolute lengths |
| 动画类型 | a position |
<position>where
<position> = [ [ left | center | right ] || [ top | center | bottom ] | [ left | center | right | <length-percentage> ] [ top | center | bottom | <length-percentage> ]? | [ [ left | right ] <length-percentage> ] && [ [ top | bottom ] <length-percentage> ] ]where
<length-percentage> = <length> | <percentage>
<div id="container">
<div>
<p>At coordinate (0, 0)</p>
<div class="scrollContainer destination0">
<div>1</div>
<div>2</div>
<div>3</div>
</div>
</div>
<div>
<p>At coordinate (25, 0)</p>
<div class="scrollContainer destination25">
<div>1</div>
<div>2</div>
<div>3</div>
</div>
</div>
<div>
<p>At coordinate (50, 0)</p>
<div class="scrollContainer destination50">
<div>1</div>
<div>2</div>
<div>3</div>
</div>
</div>
</div>
#container {
display: flex;
}
#container > div:nth-child(-n+2) {
margin-right: 20px;
}
.scrollContainer {
width: 100px;
overflow: auto;
white-space: nowrap;
scroll-snap-points-x: repeat(100%);
scroll-snap-type: mandatory;
scroll-snap-destination: 20px 0;
font-size: 0;
}
.destination0 {
scroll-snap-destination: 0 0;
}
.destination25 {
scroll-snap-destination: 25px 0;
}
.destination50 {
scroll-snap-destination: 50px 0;
}
.scrollContainer > div {
width: 100px;
height: 100px;
display: inline-block;
line-height: 100px;
text-align: center;
font-size: 50px;
}
.scrollContainer > div:nth-child(even) {
background-color: #87EA87;
}
.scrollContainer > div:nth-child(odd) {
background-color: #87CCEA;
}
Not part of any standard.
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
scroll-snap-destination
弃用
非标
|
Chrome 不支持 No | Edge 不支持 No | Firefox 不支持 39 — 68 | IE 不支持 No | Opera 不支持 No | Safari 不支持 No | WebView Android 不支持 No | Chrome Android 不支持 No | Firefox Android 不支持 39 — 68 | Opera Android 不支持 No | Safari iOS 不支持 No | Samsung Internet Android 不支持 No |
不支持
非标。预期跨浏览器支持较差。
弃用。不要用于新网站。
scroll-margin
scroll-margin-block
scroll-margin-block-end
scroll-margin-block-start
scroll-margin-bottom
scroll-margin-inline
scroll-margin-inline-end
scroll-margin-inline-start
scroll-margin-left
scroll-margin-right
scroll-margin-top
scroll-padding
scroll-padding-block
scroll-padding-block-end
scroll-padding-block-start
scroll-padding-bottom
scroll-padding-inline
scroll-padding-inline-end
scroll-padding-inline-start
scroll-padding-left
scroll-padding-right
scroll-padding-top
scroll-snap-align
scroll-snap-coordinate
scroll-snap-destination
scroll-snap-points-x
scroll-snap-points-y
scroll-snap-stop
scroll-snap-type
scroll-snap-type-x
scroll-snap-type-y