CSS

scroll-snap-points-x

弃用

该功能已从Web标准中删除。尽管一些浏览器可能仍然支持它,但它正在被丢弃。避免使用它并尽可能更新现有的代码; 请参阅本页面底部的兼容性表格来指导您的决定。请注意,此功能可能随时停止工作。

scroll-snap-points-x CSS属性定义的捕捉点它们被施加到滚动容器的内容物中的水平位置。

/* Keyword value */ scroll-snap-points-x: none; /* Repeating snap points */ scroll-snap-points-x: repeat(400px /* Global values */ scroll-snap-points-x: inherit; scroll-snap-points-x: initial; scroll-snap-points-x: unset;

Initial valuenone
应用对象scroll containers
是否可继承no
百分比值relative to same axis of the padding-box of the scroll container
媒体interactive
计算值as specified, but with relative lengths converted into absolute lengths
动画类型discrete
规范顺序the unique non-ambiguous order defined by the formal grammar

语法

none滚动容器不定义任何捕捉点。滚动容器内的元素仍可以代表滚动容器定义捕捉点。repeat(<length-percentage>)定义从容器的相关起始边缘开始定义捕捉点的间隔。只允许积极的长度。百分比是指容器的宽度。

形式语法

none | repeat( <length-percentage> )where <length-percentage> = <length> | <percentage>

例子

HTML内容

<div id="container">   <div>1</div>   <div>2</div>   <div>3</div> </div>

CSS内容

#container {   width: 200px;   overflow: auto;   white-space: nowrap;   scroll-snap-points-x: repeat(100%   scroll-snap-type: mandatory;   font-size: 0; } #container > div { width: 200px; height: 200px; display: inline-block; line-height: 200px; text-align: center; font-size: 100px; } #container > div:nth-child(even) { background-color: #87ea87; } #container > div:nth-child(odd) { background-color: #87ccea; }

规范

这个属性曾经在CSS Scroll Snap Points Module早期版本中定义过,但后来从规范中删除了,以支持基于元素的snapping

浏览器兼容性

FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
Basic supportNo support39.0 (39.0)No supportNo support9-webkit

FeatureAndroidFirefox Mobile (Gecko)Firefox OSIE PhoneOpera MobileSafari Mobile
Basic supportNo support39.0 (39.0)139.0 (39.0)No supportNo support9-webkit