aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/element/scrollintoview
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/element/scrollintoview
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/element/scrollintoview')
-rw-r--r--files/zh-cn/web/api/element/scrollintoview/index.html78
1 files changed, 78 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/element/scrollintoview/index.html b/files/zh-cn/web/api/element/scrollintoview/index.html
new file mode 100644
index 0000000000..3cba87dabf
--- /dev/null
+++ b/files/zh-cn/web/api/element/scrollintoview/index.html
@@ -0,0 +1,78 @@
+---
+title: Element.scrollIntoView()
+slug: Web/API/Element/scrollIntoView
+translation_of: Web/API/Element/scrollIntoView
+---
+<div>{{APIRef("DOM")}}</div>
+
+<div><span class="seoSummary">{{domxref("Element")}} </span>接口的scrollIntoView()方法会滚动元素的父容器,使被调用scrollIntoView()的元素对用户可见。</div>
+
+<h2 id="语法">语法</h2>
+
+<pre class="syntaxbox notranslate">element.scrollIntoView(); // 等同于element.scrollIntoView(true)
+element.scrollIntoView(alignToTop); // Boolean型参数
+element.scrollIntoView(scrollIntoViewOptions); // Object型参数</pre>
+
+<h3 id="参数">参数</h3>
+
+<dl>
+ <dt><code>alignToTop</code>{{optional_inline}}</dt>
+ <dd>一个{{jsxref("Boolean")}}值:
+ <ul>
+ <li>如果为<code>true</code>,元素的顶端将和其所在滚动区的可视区域的顶端对齐。相应的 <code>scrollIntoViewOptions: {block: "start", inline: "nearest"}</code>。这是这个参数的默认值。</li>
+ <li>如果为<code>false</code>,元素的底端将和其所在滚动区的可视区域的底端对齐。相应的<code>scrollIntoViewOptions: {block: "end", inline: "nearest"}</code>。</li>
+ </ul>
+ </dd>
+ <dt><code>scrollIntoViewOptions</code> {{optional_inline}} {{experimental_inline}}</dt>
+ <dd>一个包含下列属性的对象:</dd>
+ <dd>
+ <dl>
+ <dt><code>behavior</code> {{optional_inline}}</dt>
+ <dd>定义动画过渡效果, <code>"auto"</code>或 <code>"smooth"</code> 之一。默认为 <code>"auto"</code>。</dd>
+ <dt><code>block</code> {{optional_inline}}</dt>
+ <dd>定义垂直方向的对齐, <code>"start"</code>, <code>"center"</code>, <code>"end"</code>, 或 <code>"nearest"</code>之一。默认为 <code>"start"</code>。</dd>
+ <dt><code>inline</code> {{optional_inline}}</dt>
+ <dd>定义水平方向的对齐, <code>"start"</code>, <code>"center"</code>, <code>"end"</code>, 或 <code>"nearest"</code>之一。默认为 <code>"nearest"</code>。</dd>
+ </dl>
+ </dd>
+</dl>
+
+<h2 id="示例">示例</h2>
+
+<pre class="notranslate"><code>var element = document.getElementById("box");
+
+element.scrollIntoView();
+element.scrollIntoView(false);
+element.scrollIntoView({block: "end"});
+element.scrollIntoView({behavior: "smooth", block: "end", inline: "nearest"});</code></pre>
+
+<h2 id="注意">注意</h2>
+
+<p>取决于其它元素的布局情况,此元素可能不会完全滚动到顶端或底端。</p>
+
+<h2 id="规范">规范</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th>Specification</th>
+ <th>Status</th>
+ <th>Comment</th>
+ </tr>
+ <tr>
+ <td>{{SpecName("CSSOM View", "#dom-element-scrollintoview", "Element.scrollIntoView()")}}</td>
+ <td>{{Spec2("CSSOM View")}}</td>
+ <td>Initial definition</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="浏览器兼容性">浏览器兼容性</h2>
+
+<p>{{Compat("api.Element.scrollIntoView")}}</p>
+
+<h2 id="相关内容">相关内容</h2>
+
+<ul>
+ <li>{{domxref("Element.scrollIntoViewIfNeeded()")}}<a href="https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoViewIfNeeded"> </a>{{non-standard_inline}}</li>
+</ul>