IntersectionObserver.observe()

这篇翻译不完整。请帮忙从英语翻译这篇文章

这是一个实验中的功能
此功能某些浏览器尚在开发中,请参考浏览器兼容性表格以得到在不同浏览器中适合使用的前缀。由于该功能对应的标准文档可能被重新修订,所以在未来版本的浏览器中该功能的语法和行为可能随之改变。

IntersectionObserver 对象的observe() 方法向IntersectionObserver对象监听的目标集合添加一个元素。一个监听者有一组阈值和一个根, 但是可以监视多个目标元素,以查看这些目标元素可见区域的变化。调用IntersectionObserver.unobserve()方法可以停止观察元素。

当指定元素的可见区域超过监听者的可见区域阈值之一时(阈值列表IntersectionObserver.thresholds),监听者的回调会被传入代表当前发生的交叉变化IntersectionObserverEntry并执行。请注意,这种设计允许通过调用一次回调,给回调传入IntersectionObserverEntry对象数组,来实现同时处理多个被监听元素的交叉变化。

语法

IntersectionObserver.observe(targetElement);

参数

targetElement
可见性区域被监控的元素element
此元素必须是根元素的后代 (如果根元素为视窗,则该元素必须被当前文档包含)。

返回值

undefined.

Examples

<<<...>>>

Specifications

Specification Status Comment
Intersection Observer
IntersectionObserver.observe()
Working Draft Initial definition.

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
observe
Experimental
Chrome Full support 51Edge Full support 15Firefox Full support 55
Full support 55
No support 53 — 55
Disabled
Disabled From version 53 until version 55 (exclusive): this feature is behind the dom.IntersectionObserver.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
IE No support NoOpera Full support YesSafari Full support 12.1WebView Android Full support 51Chrome Android Full support 51Edge Mobile Full support YesFirefox Android ? Opera Android ? Safari iOS Full support 12.2Samsung Internet Android Full support 5.0

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
Experimental. Expect behavior to change in the future.
Experimental. Expect behavior to change in the future.
User must explicitly enable this feature.
User must explicitly enable this feature.

See also

文档标签和贡献者

此页面的贡献者: callmezhenzhen
最后编辑者: callmezhenzhen,