CSS

滚动界限种类 | scroll-snap-type

scroll-snap-type

这是一种实验技术

由于该技术的规格不稳定,请查看各种浏览器的兼容性表格以供使用。另外请注意,随着规范的变化,实验技术的语法和行为在未来版本的浏览器中可能会发生变化。

scroll-snap-type CSS属性定义捕捉点是如何严格的情况下,有一个滚动容器上强制执行。

指定用于执行这些捕捉点的精确动画或物理属性不属于此属性,而是留给用户代理。

/* Keyword values */ scroll-snap-type: none; scroll-snap-type: mandatory; scroll-snap-type: proximity; /* Global values */ scroll-snap-type: inherit; scroll-snap-type: initial; scroll-snap-type: unset;

初始值 none
适用于滚动容器
遗传没有
媒体 interactive
计算值作为指定
动画类型离散的
规范的顺序形式语法定义的独特的非模糊顺序

语法

none当滚动此滚动容器的可视视口时,它必须忽略捕捉点。

形式语法

none | mandatory | proximity

HTML内容

<div class="container mandatoryScrollSnapping">   <div>1</div>   <div>2</div>   <div>3</div> </div> <div class="container proximityScrollSnapping">   <div>1</div>   <div>2</div>   <div>3</div> </div>

CSS内容

.container { width: 100%; overflow: auto; white-space: nowrap; scroll-snap-points-x: repeat(100% scroll-snap-type: mandatory; font-size: 0; } .mandatoryScrollSnapping { margin-bottom: 20px; scroll-snap-type: mandatory; } .proximityScrollSnapping { scroll-snap-type: proximity; } .container > div { width: 100%; height: 100px; display: inline-block; line-height: 100px; text-align: center; font-size: 50px; } .container > div:nth-child(even) { background-color: #87EA87; } .container > div:nth-child(odd) { background-color: #87CCEA; }

规范

SpecificationStatusComment
CSS Scroll Snap Module Level 1The definition of 'scroll-snap-type' in that specification.Candidate RecommendationInitial definition

浏览器兼容性

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

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