aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/element/scroll/index.html
blob: 69e3f5f738a229bded1898dd38e6cd917ef57779 (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
---
title: Element.scroll()
slug: Web/API/Element/scroll
translation_of: Web/API/Element/scroll
---
<div>{{APIRef}}</div>

<p> <strong><code>scroll()</code></strong> 方法是用于在给定的元素中滚动到某个特定坐标的 {{domxref("Element")}} 接口。</p>

<h2 id="Syntax" name="Syntax">Syntax</h2>

<pre class="syntaxbox">element.scroll(<em>x-coord</em>, <em>y-coord</em>)
element.scroll(<em>options</em>)
</pre>

<h3 id="Parameters" name="Parameters">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">// 在元素上方显示1000像素
element.scroll(0, 1000);
</pre>

<p>使用 <code>options</code>:</p>

<pre class="brush: js">element.scroll({
  top: 100,
  left: 100,
  behavior: 'smooth'
});</pre>

<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-element-scroll-options-options', 'element.scroll()') }}</td>
   <td>{{ Spec2('CSSOM View') }}</td>
   <td>
    <p>Initial definition.</p>
   </td>
  </tr>
 </tbody>
</table>

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



<p>{{Compat("api.Element.scroll")}}</p>