aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/window/scrollby/index.html
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
commit33058f2b292b3a581333bdfb21b8f671898c5060 (patch)
tree51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/api/window/scrollby/index.html
parent8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff)
downloadtranslated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip
initial commit
Diffstat (limited to 'files/zh-cn/web/api/window/scrollby/index.html')
-rw-r--r--files/zh-cn/web/api/window/scrollby/index.html84
1 files changed, 84 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/window/scrollby/index.html b/files/zh-cn/web/api/window/scrollby/index.html
new file mode 100644
index 0000000000..fea5cc42e3
--- /dev/null
+++ b/files/zh-cn/web/api/window/scrollby/index.html
@@ -0,0 +1,84 @@
+---
+title: Window.scrollBy()
+slug: Web/API/Window/scrollBy
+tags:
+ - 全局方法
+translation_of: Web/API/Window/scrollBy
+---
+<p>{{ APIRef() }}</p>
+
+<h2 id="Summary" name="Summary">摘要</h2>
+
+<p>在窗口中按指定的偏移量滚动文档。</p>
+
+<h2 id="Syntax" name="Syntax">语法</h2>
+
+<pre>window.scrollBy(<em>x-coord</em>, <em>y-coord</em>);
+window.scrollBy(<em>options</em>)
+</pre>
+
+<h3 id="Parameters" name="Parameters">参数</h3>
+
+<ul>
+ <li><code>X</code> 是水平滚动的偏移量,单位:像素。</li>
+ <li><code>Y</code> 是垂直滚动的偏移量,单位:像素。</li>
+</ul>
+
+<p>正数坐标会朝页面的右下方滚动,负数坐标会滚向页面的左上方。</p>
+
+<ul>
+ <li><code>options</code> 是一个包含三个属性的对象:</li>
+</ul>
+
+<ol>
+ <li><code><em>top</em></code> 等同于  <code><em>y-coord</em></code></li>
+ <li><code><font face="consolas, Liberation Mono, courier, monospace">left</font></code> 等同于  <code>x<em>-coord</em></code></li>
+ <li><code><em>behavior</em></code><em>  表示滚动行为,支持参数:<code>smooth</code> (平滑滚动),<code>instant</code> (瞬间滚动),默认值 <code>auto</code>,效果等同于 <code>instant</code></em></li>
+</ol>
+
+<h2 id="Example" name="Example">例子</h2>
+
+<p>向下滚动一页:</p>
+
+<pre><code>window.scrollBy(0, window.innerHeight);</code>
+</pre>
+
+
+
+<p>向上滚动一页:</p>
+
+<pre><code>window.scrollBy(0, -window.innerHeight);</code></pre>
+
+
+
+<p>使用 options:</p>
+
+<pre><code>window.scrollBy({
+ top: 100,
+  left: 100,
+ behavior: "smooth"
+});</code>
+</pre>
+
+<h2 id="Notes" name="Notes">注意</h2>
+
+<p><a href="/en-US/docs/DOM/Window.scrollBy">window.scrollBy</a> 滚动指定的距离,而 <a href="/en-US/docs/DOM/Window.scroll">window.scroll</a> 滚动至文档中的绝对位置。另外还有 <a href="/en-US/docs/DOM/Window.scrollByLines">window.scrollByLines</a>, <a href="/en-US/docs/DOM/Window.scrollByPages">window.scrollByPages</a></p>
+
+<h2 id="Specification" name="Specification">规范</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('CSSOM View', '#dom-window-scrollby', 'window.scrollBy()') }}</td>
+ <td>{{ Spec2('CSSOM View') }}</td>
+ <td>初次定义</td>
+ </tr>
+ </tbody>
+</table>