aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/intersectionobserver/unobserve/index.html
blob: 45f8e1f5b5176a9070ed345e481be003aaa2765b (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
---
title: IntersectionObserver.unobserve()
slug: Web/API/IntersectionObserver/unobserve
tags:
  - API
  - Intersection
  - Intersection Observer
  - Intersection Observer API
  - IntersectionObserver
  - unobserve
translation_of: Web/API/IntersectionObserver/unobserve
browser-compat: api.IntersectionObserver.unobserve
---
<div>{{APIRef("Intersection Observer API")}}</div>

<p>{{domxref("IntersectionObserver")}}<code>unobserve()</code>
  方法命令<code>IntersectionObserver</code>停止对一个元素的观察。
</p>

<h2 id="语法">语法</h2>

<pre
  class="brush: js"><em>IntersectionObserver</em>.unobserve(<em>target</em>);</pre>

<h3 id="参数">参数</h3>

<dl>
 <dt><code>target</code></dt>
 <dd>要取消观察的目标,如果没有提供,方法不做任何事情,也不会抛出异常。</dd>
</dl>

<h3 id="返回值">返回值</h3>

<p><code>undefined</code>.</p>

<dl>
</dl>

<h2 id="例子">例子</h2>

<p>下面代码段展示了一个观察器被创建,一个元素被观察,以及取消观察的过程。</p>

<pre class="brush: js">var observer = new IntersectionObserver(callback);
observer.observe(document.getElementById("elementToObserve"));

/* ... */

observer.unobserve(document.getElementById("elementToObserve"));</pre>

<h2 id="说明">说明</h2>

{{Specifications}}

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

<p>{{Compat}}</p>

<h2 id="另请参阅">另请参阅</h2>

<ul>
 <li><a href="/en-US/docs/Web/API/Intersection_Observer_API">Intersection Observer API</a></li>
 <li>{{domxref("IntersectionObserver.observe()")}}</li>
</ul>