IntersectionObserver

open class IntersectionObserver(callback: IntersectionObserverCallback, options: IntersectionObserverInit = definedExternally)(source)

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.

MDN Reference

Constructors

Link copied to clipboard
constructor(callback: IntersectionObserverCallback, options: IntersectionObserverInit = definedExternally)

Properties

Link copied to clipboard

The root read-only property of the IntersectionObserver interface identifies the Element or Document whose bounds are treated as the bounding box of the viewport for the element which is the observer's target.

Link copied to clipboard

The rootMargin read-only property of the IntersectionObserver interface is a string with syntax similar to that of the CSS margin property.

Link copied to clipboard

The scrollMargin read-only property of the IntersectionObserver interface adds a margin to all nested scroll container within the root element, including the root element if it is a scroll container.

Link copied to clipboard

The thresholds read-only property of the IntersectionObserver interface returns the list of intersection thresholds that was specified when the observer was instantiated with IntersectionObserver.IntersectionObserver.

Functions

Link copied to clipboard

The disconnect() method of the IntersectionObserver interface stops the observer watching all of its target elements for visibility changes.

Link copied to clipboard
fun observe(target: Element)

The observe() method of the IntersectionObserver interface adds an element to the set of target elements being watched by the IntersectionObserver.

Link copied to clipboard

The takeRecords() method of the IntersectionObserver interface returns an array of IntersectionObserverEntry objects, one for each targeted element which has experienced an intersection change since the last time the intersections were checked, either explicitly through a call to this method or implicitly by an automatic call to the observer's callback.

Link copied to clipboard
fun unobserve(target: Element)

The unobserve() method of the IntersectionObserver interface instructs the IntersectionObserver to stop observing the specified target element.