The IntersectionObserver()
constructor creates and returns a new IntersectionObserver
object.
The rootMargin
, if specified, is checked to ensure it's syntactically correct. If not specified, or an empty string, the default is 0px 0px 0px 0px
.
The threshold
s, if specified, are checked to ensure that they're all in the range 0.0 and 1.0 inclusive, and the threshold list is sorted in ascending numeric order. If the threshold list is empty, it's set to the array [0.0]
.
new IntersectionObserver(callback)
new IntersectionObserver(callback, options)
A new IntersectionObserver
which can be used to watch for the visibility of a target element within the specified root
crossing through any of the specified visibility threshold
s. Call its observe()
method to begin watching for the visibility changes on a given target.
This example creates a new intersection observer which calls the function myObserverCallback
every time the visible area of the element being observed changes by at least 10%.
let observer = new IntersectionObserver(myObserverCallback,
{threshold: 0.1});