From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../web/css/scroll-snap-destination/index.html | 192 +++++++++++++++++++++ 1 file changed, 192 insertions(+) create mode 100644 files/zh-cn/web/css/scroll-snap-destination/index.html (limited to 'files/zh-cn/web/css/scroll-snap-destination/index.html') diff --git a/files/zh-cn/web/css/scroll-snap-destination/index.html b/files/zh-cn/web/css/scroll-snap-destination/index.html new file mode 100644 index 0000000000..8e33857321 --- /dev/null +++ b/files/zh-cn/web/css/scroll-snap-destination/index.html @@ -0,0 +1,192 @@ +--- +title: scroll-snap-destination +slug: Web/CSS/scroll-snap-destination +translation_of: Web/CSS/scroll-snap-destination +--- +
{{CSSRef}}{{SeeCompatTable}}
+ +

摘要

+ +

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

+ +

{{cssinfo}}

+ +

语法

+ +
/* <位置>值 */
+scroll-snap-destination: 400px 600px;
+
+/* 全局值 */
+scroll-snap-destination: inherit;
+scroll-snap-destination: initial;
+scroll-snap-destination: unset;
+
+ +

取值

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

正式语法

+ +
{{csssyntax}}
+ +

示例

+ +

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

{{EmbedLiveSample("Example", "100%", "170")}}

+ +

规范

+ + + + + + + + + + + + + + + + +
规范名称状态评论
{{SpecName("CSS Scroll Snap Points", "#propdef-scroll-snap-destination", "scroll-snap-destination")}}{{Spec2("CSS Scroll Snap Points")}}Initial definition
+ +

浏览器兼容性

+ +

{{CompatibilityTable}}

+ +
+ + + + + + + + + + + + + + + + + + + +
特性ChromeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
支持度{{CompatUnknown}}{{CompatGeckoDesktop("39.0")}}{{CompatNo}}{{CompatNo}}{{CompatNo}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
特性AndroidFirefox Mobile (Gecko)Firefox OSIE PhoneOpera MobileSafari Mobile
支持度{{CompatNo}}{{CompatGeckoMobile("39.0") }}[1]{{CompatGeckoMobile("39.0") }}{{CompatNo}}{{CompatNo}}{{CompatNo}}
+
+ +

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

-- cgit v1.2.3-54-g00ecf