aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/element/scrollto/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'files/zh-cn/web/api/element/scrollto/index.html')
-rw-r--r--files/zh-cn/web/api/element/scrollto/index.html77
1 files changed, 77 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/element/scrollto/index.html b/files/zh-cn/web/api/element/scrollto/index.html
new file mode 100644
index 0000000000..19f369bd0b
--- /dev/null
+++ b/files/zh-cn/web/api/element/scrollto/index.html
@@ -0,0 +1,77 @@
+---
+title: Element.scrollTo()
+slug: Web/API/Element/scrollTo
+tags:
+ - API
+ - Element
+ - Method
+ - Reference
+ - scrollTo
+translation_of: Web/API/Element/scrollTo
+---
+<div>{{ APIRef }}<br>
+{{domxref("Element")}} 的<code><strong>scrollTo()</strong></code><strong> </strong>方法可以使界面滚动到给定元素的指定坐标位置。</div>
+
+<h2 id="Syntax" name="Syntax">语法</h2>
+
+<pre class="syntaxbox">element.scrollTo(<em>x-coord</em>, <em>y-coord</em>)
+element.scrollTo(<em>options</em>)
+</pre>
+
+<h3 id="Parameters" name="Parameters">参数</h3>
+
+<ul>
+ <li><code>x-coord</code> 是期望滚动到位置水平轴上距元素左上角的像素。</li>
+ <li><code>y-coord</code> 是期望滚动到位置竖直轴上距元素左上角的像素。</li>
+</ul>
+
+<p>- or -</p>
+
+<ul>
+ <li><code>options</code> 是一个{{domxref("ScrollToOptions")}}对象。</li>
+</ul>
+
+<h2 id="Example" name="Example">例子</h2>
+
+<pre class="brush:js">element.scrollTo(0, 1000);
+</pre>
+
+<p>使用 <code>options</code>:</p>
+
+<pre class="brush: js">element.scrollTo({
+ top: 100,
+ left: 100,
+ behavior: 'smooth'
+});</pre>
+
+<h2 id="Specifications" name="Specifications">规范</h2>
+
+<table class="standard-table">
+ <thead>
+ <tr>
+ <th scope="col">Specification</th>
+ <th scope="col">Status</th>
+ <th scope="col">Comment</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>{{ SpecName('CSSOM View', '#dom-element-scrollto-options-options', 'element.scrollTo()') }}</td>
+ <td>{{ Spec2('CSSOM View') }}</td>
+ <td>Initial definition.</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="浏览器兼容性">浏览器兼容性</h2>
+
+
+
+<p>{{Compat("api.Element.scrollTo")}}</p>
+
+<h2 id="参考">参考</h2>
+
+<ul>
+ <li>{{domxref("Element.scrollTop")}}, {{domxref("Element.scrollLeft")}}</li>
+ <li>{{domxref("Window.scrollTo()")}}</li>
+</ul>