This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
The IntersectionObserver interface of the Intersection Observer API provides a way to asynchronously observe changes in the intersection of a target element with an ancestor element or with a top-level document's viewport. The ancestor element or viewport is referred to as the root.
When an IntersectionObserver is created, it's configured to watch for given ratios of visibility within the root. The configuration cannot be changed once the IntersectionObserver is created, so a given observer object is only useful for watching for specific changes in degree of visibility; however, you can watch multiple target elements with the same observer.
IntersectionObserver.IntersectionObserver()IntersectionObserver object which will execute a specified callback function when it detects that a target element's visibility has crossed one or more thresholds.IntersectionObserver.root Read only
element being observed. If no value was passed to the constructor or this is null, the top-level document's viewport is used.IntersectionObserver.rootMargin Read only
px) or as a percentage (%). The default is "0px 0px 0px 0px".IntersectionObserver.thresholds Read only
IntersectionObserver.disconnect()IntersectionObserver object from observing any target.IntersectionObserver.observe()IntersectionObserver a target element to observe.IntersectionObserver.takeRecords()IntersectionObserverEntry objects for all observed targets and stops observing all of them.IntersectionObserver.unobserve()IntersectionObserver to stop observing a particular target element.var intersectionObserver = new IntersectionObserver(function(entries) {
// If intersectionRatio is 0, the target is out of view
// and we do not need to do anything.
if (entries[0].intersectionRatio <= 0) return;
loadItems(10);
console.log('Loaded new items');
});
// start observing
intersectionObserver.observe(document.querySelector('.scrollerFooter')); | Specification | Status | Comment |
|---|---|---|
| Intersection Observer | Working Draft |
| Feature | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|---|
| Basic support | 51 | 15 |
53 — 551 55 |
No | ? | ? |
IntersectionObserver() constructor |
51 | 15 |
53 — 551 55 |
No | ? | ? |
root |
51 | 15 |
53 — 551 55 |
No | ? | ? |
rootMargin |
51 | 15 |
53 — 551 55 |
No | ? | ? |
thresholds |
51 | 15 |
53 — 551 55 |
No | ? | ? |
disconnect |
51 | 152 |
53 — 551 55 |
No | ? | ? |
observe |
51 | 15 |
53 — 551 55 |
No | ? | ? |
takeRecords |
51 | 152 |
53 — 551 55 |
No | ? | ? |
unobserve |
51 | 152 |
53 — 551 55 |
No | ? | ? |
| Feature | Android webview | Chrome for Android | Edge mobile | Firefox for Android | IE mobile | Opera Android | iOS Safari |
|---|---|---|---|---|---|---|---|
| Basic support | 51 | 51 | Yes | ? | No | ? | ? |
IntersectionObserver() constructor |
51 | 51 | Yes | ? | No | ? | ? |
root |
51 | 51 | Yes | ? | No | ? | ? |
rootMargin |
51 | 51 | Yes | ? | No | ? | ? |
thresholds |
51 | 51 | Yes | ? | No | ? | ? |
disconnect |
51 | 51 | Yes | ? | No | ? | ? |
observe |
51 | 51 | Yes | ? | No | ? | ? |
takeRecords |
51 | 51 | Yes | ? | No | ? | ? |
unobserve |
51 | 51 | Yes | ? | No | ? | ? |
1. 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.
2. Available since Windows Insider Preview Build 14986
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver