aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/css/scroll-snap-coordinate/index.html
blob: 76f9ff866668bca47e568ea63863f3903346a9a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
---
title: scroll-snap-coordinate
slug: Web/CSS/scroll-snap-coordinate
tags:
  - CSS
  - css snap
translation_of: Web/CSS/scroll-snap-coordinate
---
<div>{{CSSRef}}{{SeeCompatTable}}</div>

<h2 id="摘要">摘要</h2>

<p><strong><code>scroll-snap-coordinate</code></strong> <a href="/en-US/docs/Web/CSS">CSS</a>属性结合元素的最近的祖先元素滚动容器的{{cssxref("scroll-snap-destination")}} 定义的轴,定义了元素中x和y坐标偏移的位置。</p>

<p>如果元素已经变型,snap坐标也以相同的方式进行变型,为了使元素的snap点向元素一样被显示。</p>

<div>{{cssinfo}}</div>

<h2 id="语法">语法</h2>

<pre class="brush: css">/* 关键值 */
scroll-snap-coordinate: none;

/* &lt;位置&gt;值 */
scroll-snap-coordinate: 50px 50px;                   /* 单坐标 */
scroll-snap-coordinate: 100px 100px, 100px bottom;   /* 多坐标 */

/* 全局值 */
scroll-snap-coordinate: inherit;
scroll-snap-coordinate: initial;
scroll-snap-coordinate: unset;
</pre>

<h3 id="赋值">赋值</h3>

<dl>
 <dt><code>none</code></dt>
 <dd>定义元素不提供一个snap点。</dd>
 <dt><code>&lt;position&gt;</code></dt>
 <dd>定义从元素核模型边框边缘开始偏移的snap坐标。每一对值中,第一个值给定了snap坐标的x坐标,第二个值为它的y坐标。</dd>
</dl>

<h3 id="正式语法">正式语法</h3>

<pre class="syntaxbox">{{csssyntax}}</pre>

<h2 id="示例">示例</h2>

<h3 id="HTML内容">HTML内容</h3>

<pre class="brush: html">&lt;div id="container"&gt;
  &lt;div&gt;
    &lt;p&gt;At coordinate (0, 0)&lt;/p&gt;
    &lt;div class="scrollContainer coordinate0"&gt;
      &lt;div&gt;1&lt;/div&gt;
      &lt;div&gt;2&lt;/div&gt;
      &lt;div&gt;3&lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;

  &lt;div&gt;
    &lt;p&gt;At coordinate (25, 0)&lt;/p&gt;
    &lt;div class="scrollContainer coordinate25"&gt;
      &lt;div&gt;1&lt;/div&gt;
      &lt;div&gt;2&lt;/div&gt;
      &lt;div&gt;3&lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;

  &lt;div&gt;
    &lt;p&gt;At coordinate (50, 0)&lt;/p&gt;
    &lt;div class="scrollContainer coordinate50"&gt;
      &lt;div&gt;1&lt;/div&gt;
      &lt;div&gt;2&lt;/div&gt;
      &lt;div&gt;3&lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;
</pre>

<h3 id="CSS内容">CSS内容</h3>

<pre class="brush: css">#container {
  display: flex;
}

#container &gt; div:nth-child(-n+2) {
  margin-right: 20px;
}

.scrollContainer {
  width: 100px;
  overflow: auto;
  white-space: nowrap;
  scroll-snap-type: mandatory;
  font-size: 0;
}

.scrollContainer &gt; div {
  width: 100px;
  height: 100px;
  display: inline-block;
  line-height: 100px;
  text-align: center;
  font-size: 50px;
}

.coordinate0 &gt; div {
  scroll-snap-coordinate: 0 0;
}

.coordinate25 &gt; div {
  scroll-snap-coordinate: 25px 0;
}

.coordinate50 &gt; div {
  scroll-snap-coordinate: 50px 0;
}

.scrollContainer &gt; div:nth-child(even) {
  background-color: #87ea87;
}

.scrollContainer &gt; div:nth-child(odd) {
  background-color: #87ccea;
}</pre>

<p>{{EmbedLiveSample("Example", "100%", "170")}}</p>

<h2 id="规范">规范</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">规范名称</th>
   <th scope="col">状态</th>
   <th scope="col">评论</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName("CSS Scroll Snap Points", "#propdef-scroll-snap-coordinate", "scroll-snap-coordinate")}}</td>
   <td>{{Spec2("CSS Scroll Snap Points")}}</td>
   <td>Initial definition</td>
  </tr>
 </tbody>
</table>

<h2 id="浏览器兼容性">浏览器兼容性</h2>

<p>{{CompatibilityTable}}</p>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>特性</th>
   <th>Chrome</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari (WebKit)</th>
  </tr>
  <tr>
   <td>支持度</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatGeckoDesktop("39.0")}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>特性</th>
   <th>Android</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>Firefox OS</th>
   <th>IE Phone</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>支持度</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatGeckoMobile("39.0") }}<sup>[1]</sup></td>
   <td>{{CompatGeckoMobile("39.0") }}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
  </tr>
 </tbody>
</table>
</div>

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