From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- files/zh-cn/web/api/window/scrollto/index.html | 58 ++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 files/zh-cn/web/api/window/scrollto/index.html (limited to 'files/zh-cn/web/api/window/scrollto') diff --git a/files/zh-cn/web/api/window/scrollto/index.html b/files/zh-cn/web/api/window/scrollto/index.html new file mode 100644 index 0000000000..715e3f0190 --- /dev/null +++ b/files/zh-cn/web/api/window/scrollto/index.html @@ -0,0 +1,58 @@ +--- +title: Window.scrollTo() +slug: Web/API/Window/scrollTo +translation_of: Web/API/Window/scrollTo +--- +
{{ APIRef }}
+ +

摘要

+ +

滚动到文档中的某个坐标。

+ +

语法

+ +
window.scrollTo(x-coord,y-coord )
+
+window.scrollTo(options)
+ +

参数

+ + + +
    +
  1. top 等同于  y-coord
  2. +
  3. left 等同于  x-coord
  4. +
  5. behavior  类型String,表示滚动行为,支持参数 smooth(平滑滚动),instant(瞬间滚动),默认值auto,实测效果等同于instant
  6. +
+ +
+
+ +

例子

+ +
window.scrollTo( 0, 1000 );
+
+// 设置滚动行为改为平滑的滚动
+window.scrollTo({
+    top: 1000,
+    behavior: "smooth"
+});
+
+ +

注意

+ +

该函数实际上和 window.scroll是一样的。 相对滚动可以参考 window.scrollBywindow.scrollByLines,和 window.scrollByPages

+ +

规范

+ +

{{dom0}}

+ +

浏览器兼容性

+ + + +

{{Compat("api.Window.scrollTo")}}

-- cgit v1.2.3-54-g00ecf