Please note, this is a STATIC archive of website developer.mozilla.org from November 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

scroll-snap-destination

这是一个实验中的功能
此功能某些浏览器尚在开发中,请参考浏览器兼容性表格以得到在不同浏览器中适合使用的前缀。由于该功能对应的标准文档可能被重新修订,所以在未来版本的浏览器中该功能的语法和行为可能随之改变。

摘要

scroll-snap-destination CSS属性定义滚动容器的可视化viewport 中元素snap点的x和y坐标位置。

初始值0px 0px
适用元素scroll containers
是否是继承属性
Percentagesrelative to same axis of the padding-box of the scroll container
适用媒体interactive
计算值as specified, but with relative lengths converted into absolute lengths
是否适用于 CSS 动画yes, as a position
正规顺序the unique non-ambiguous order defined by the formal grammar

语法

/* <位置>值 */
scroll-snap-destination: 400px 600px;

/* 全局值 */
scroll-snap-destination: inherit;
scroll-snap-destination: initial;
scroll-snap-destination: unset;

取值

<position>
定义从滚动容器的可视视图边缘开始偏移的snap坐标。第一个值给定了snap坐标的x坐标,第二个值为它的y坐标。

正式语法

<position>

示例

HTML内容

<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>

CSS内容

#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;
}

规范

规范名称 状态 评论
CSS Scroll Snap Points Module Level 1
scroll-snap-destination
Working Draft Initial definition

浏览器兼容性

特性 Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
支持度 ? 39.0 (39.0) 未实现 未实现 未实现
特性 Android Firefox Mobile (Gecko) Firefox OS IE Phone Opera Mobile Safari Mobile
支持度 未实现 39.0 (39.0)[1] 39.0 (39.0) 未实现 未实现 未实现

[1] 在Firefox移动版上,从内核Gecko 39开始可用,但是低于 layout.css.vertical-text.enabled优先级,默认不可用。

文档标签和贡献者

 此页面的贡献者: rockywen
 最后编辑者: rockywen,