PUBLIC
IntersectionObserver
Constructors
Instance Properties
root
rootMargin
thresholds
Instance Methods
disconnect
observe
takeRecords
unobserve
DOM API
All API
No API set selected.
JavaScript
IntersectionObserver
:
Object
constructor
Spec
Constructors
new
IntersectionObserver
(
callback
:
Function
,
[
options
:
Object
]
) :
IntersectionObserver
callback
(
entries
:
Array
<
IntersectionObserverEntry
>,
observer
:
IntersectionObserver
) :
undefined
options
: {
root
Element
rootMargins
String
threshold
Number
}
Example:
<ul></ul> <script> // Create an observer to see when item 15 intersects the viewport const observer = new IntersectionObserver(entries => { entries.forEach(e => console.log(e.isIntersecting)); }); const list = document.querySelector('ul'); for (let i = 0; i < 30; i++) { const listItem = document.createElement('li'); listItem.textContent = 'item ' + i; list.appendChild(listItem); if (i === 15) { observer.observe(listItem); } } </script>
Run
Results:
Instance Properties
root
:
Element
readonly
rootMargin
:
String
readonly
thresholds
:
Array
<
Number
>
readonly
Instance Methods
disconnect
() :
undefined
observe
(
target
:
Element
) :
undefined
takeRecords
() :
Array
<
IntersectionObserverEntry
>
unobserve
(
target
:
Element
) :
undefined
home
license
contribute
feedback
Copyright © PUBLIC Contributors