aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/element/scrollintoviewifneeded
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/scrollintoviewifneeded
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/scrollintoviewifneeded')
-rw-r--r--files/zh-cn/web/api/element/scrollintoviewifneeded/index.html56
1 files changed, 56 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/element/scrollintoviewifneeded/index.html b/files/zh-cn/web/api/element/scrollintoviewifneeded/index.html
new file mode 100644
index 0000000000..dd419a7d6d
--- /dev/null
+++ b/files/zh-cn/web/api/element/scrollintoviewifneeded/index.html
@@ -0,0 +1,56 @@
+---
+title: Element.scrollIntoViewIfNeeded()
+slug: Web/API/Element/scrollIntoViewIfNeeded
+tags:
+ - API
+ - DOM
+ - 可视区域
+ - 方法
+ - 滚动
+ - 非标准
+translation_of: Web/API/Element/scrollIntoViewIfNeeded
+---
+<div>{{APIRef("DOM")}}{{Non-standard_header}}</div>
+
+<p><code><strong>Element.scrollIntoViewIfNeeded()</strong></code>方法用来将不在浏览器窗口的可见区域内的元素滚动到浏览器窗口的可见区域。 如果该元素已经在浏览器窗口的可见区域内,则不会发生滚动。 此方法是标准的<a href="/zh-CN/docs/Web/API/Element/scrollIntoView">Element.scrollIntoView()</a>方法的专有变体。</p>
+
+<h2 id="语法">语法</h2>
+
+<pre>element.scrollIntoViewIfNeeded(); // 等同于element.scrollIntoViewIfNeeded(true)
+element.scrollIntoViewIfNeeded(true);
+element.scrollIntoViewIfNeeded(false); </pre>
+
+<h3 id="参数">参数</h3>
+
+<dl>
+ <dt><em><code>opt_center</code></em></dt>
+ <dd>一个 {{jsxref("Boolean")}} 类型的值,默认为<code>true</code>:
+ <ul>
+ <li>如果为true,则元素将在其所在滚动区的可视区域中居中对齐。</li>
+ <li>如果为false,则元素将与其所在滚动区的可视区域最近的边缘对齐。 根据可见区域最靠近元素的哪个边缘,元素的顶部将与可见区域的顶部边缘对准,或者元素的底部边缘将与可见区域的底部边缘对准。</li>
+ </ul>
+ </dd>
+</dl>
+
+<h2 id="示例">示例</h2>
+
+<pre>var element = document.getElementById("child");
+
+element.scrollIntoViewIfNeeded();
+element.scrollIntoViewIfNeeded(true);
+element.scrollIntoViewIfNeeded(false);
+</pre>
+
+<h2 id="规范">规范</h2>
+
+<p>不属于任何规范,是一种WebKit专有的方法。</p>
+
+<h2 id="浏览器支持">浏览器支持</h2>
+
+<p>{{Compat("api.Element.scrollIntoViewIfNeeded")}}</p>
+
+<h2 id="相关链接">相关链接</h2>
+
+<ul>
+ <li><a href="https://www.w3.org/Bugs/Public/show_bug.cgi?id=17152">W3C CSSOM bug 17152: Support centering an element when scrolling into view.</a> (一个等同于 scrollIntoViewIfNeeded 的标准功能特性)</li>
+</ul>