IntersectionObserver.unobserve()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since March 2019.

IntersectionObserverunobserve() 方法命令IntersectionObserver停止对一个元素的观察。

语法

js
IntersectionObserver.unobserve(target);

参数

target

要取消观察的目标,如果没有提供,方法不做任何事情,也不会抛出异常。

返回值

undefined.

例子

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

js
var observer = new IntersectionObserver(callback);
observer.observe(document.getElementById("elementToObserve"));

/* ... */

observer.unobserve(document.getElementById("elementToObserve"));

说明

Specification
Intersection Observer
# dom-intersectionobserver-unobserve

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
unobserve

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
See implementation notes.

参见