下面有更多 "亲自试一试" 示例。
这个scroll-snap-type
指定当您停止滚动时元素如何捕捉焦点以及沿哪个方向。
为了实现滚动捕捉行为,scroll-snap-type
属性必须设置在父元素上,并且scroll-snap-align
必须在子元素上设置属性。
表中的数字指定完全支持该属性的第一个浏览器版本。
Property | |||||
---|---|---|---|---|---|
scroll-snap-type | 69.0 | 79.0 | 99.0 | 11.0 | 56.0 |
scroll-snap-type: none|x|y|block|inline|both|mandatory|proximity|initial|inherit;
Value | Description |
---|---|
none | No scroll snap effect. This is default |
x | Scroll snap effect is set on x-axis |
y | Scroll snap effect is set on y-axis |
block | Scroll snap effect is set on block direction |
inline | Scroll snap effect is set on inline direction |
both | Scroll snap effect is set on both x- and y-axis |
mandatory | Scroll will automatically move to snap point after scroll action is finished |
proximity | Similar to mandatory, but not as strict. Scroll will automatically move to snap point after scroll action is finished, but inbetween snap points there is an area without the snap effect. Depends on browser parameters. |
initial | Sets this property to its default value. Read about initial |
inherit | Inherits this property from its parent element. Read about inherit |
这个scroll-snap-type
属性在 x 轴和 y 轴上设置:
#container > div {
scroll-snap-type: both mandatory;
}
这个scroll-snap-type
属性在 x 轴和 y 轴上都设置为接近行为。使用此属性值,如果滚动操作恰好停止在两个元素的中间,则不会出现捕捉:
#container > div {
scroll-snap-type: both proximity;
}
CSS 滚动对齐属性:CSS 滚动对齐属性
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!