aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/intersectionobserver/observe/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'files/zh-cn/web/api/intersectionobserver/observe/index.html')
-rw-r--r--files/zh-cn/web/api/intersectionobserver/observe/index.html64
1 files changed, 64 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/intersectionobserver/observe/index.html b/files/zh-cn/web/api/intersectionobserver/observe/index.html
new file mode 100644
index 0000000000..fd9f581586
--- /dev/null
+++ b/files/zh-cn/web/api/intersectionobserver/observe/index.html
@@ -0,0 +1,64 @@
+---
+title: IntersectionObserver.observe()
+slug: Web/API/IntersectionObserver/observe
+translation_of: Web/API/IntersectionObserver/observe
+---
+<div>{{APIRef("Intersection Observer API")}}{{SeeCompatTable}}</div>
+
+<p><span class="seoSummary">{{domxref("IntersectionObserver")}} 对象的<code><strong>observe()</strong></code> 方法向IntersectionObserver对象监听的目标集合添加一个元素。一个监听者有一组阈值和一个根, 但是可以监视多个目标元素,以查看这些目标元素可见区域的变化。</span>调用{{domxref("IntersectionObserver.unobserve()")}}方法可以停止观察元素。</p>
+
+<p>当指定元素的可见区域超过监听者的可见区域阈值之一时(阈值列表{{domxref("IntersectionObserver.thresholds")}}),监听者的回调会被传入代表当前发生的交叉变化{{domxref("IntersectionObserverEntry")}}并执行。请注意,这种设计允许通过调用一次回调,给回调传入IntersectionObserverEntry对象数组,来实现同时处理多个被监听元素的交叉变化。</p>
+
+<h2 id="语法">语法</h2>
+
+<pre class="syntaxbox"><em>IntersectionObserver</em>.observe(<em>targetElement</em>);</pre>
+
+<h3 id="参数">参数</h3>
+
+<dl>
+ <dt><code>targetElement</code></dt>
+ <dd>可见性区域被监控的元素{{domxref("element")}}。<br>
+ 此元素必须是根元素的后代 (如果根元素为视窗,则该元素必须被当前文档包含)。</dd>
+</dl>
+
+<h3 id="返回值">返回值</h3>
+
+<p><code>undefined</code>.</p>
+
+<dl>
+</dl>
+
+<h2 id="Examples">Examples</h2>
+
+<p>&lt;&lt;&lt;...&gt;&gt;&gt;</p>
+
+<h2 id="Specifications">Specifications</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">Specification</th>
+ <th scope="col">Status</th>
+ <th scope="col">Comment</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('IntersectionObserver','#dom-intersectionobserver-observe','IntersectionObserver.observe()')}}</td>
+ <td>{{Spec2('IntersectionObserver')}}</td>
+ <td>Initial definition.</td>
+ </tr>
+ </tbody>
+</table>
+
+<div>
+<h2 id="Browser_compatibility">Browser compatibility</h2>
+
+<p class="hidden">The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> and send us a pull request.</p>
+
+<p>{{Compat("api.IntersectionObserver.observe")}}</p>
+</div>
+
+<h2 id="See_also">See also</h2>
+
+<ul>
+ <li>{{domxref("IntersectionObserver.unobserve()")}}</li>
+</ul>