# IntersectionObserver

external class IntersectionObserver (callback: IntersectionObserverCallback )(source)

This is just an implementation from this commentary of Kotlin JS issue related to the absence of Intersection Observer API

## Constructors

IntersectionObserver
Link copied to clipboard
constructor(callback: IntersectionObserverCallback )
constructor(callback: IntersectionObserverCallback , options: IntersectionObserverOptions )

## Properties

root
Link copied to clipboard
val root : Element

The Element or Document whose bounds are used as the bounding box when testing for intersection. If no root value was passed to the constructor or its value is null, the top-level document's viewport is used.

rootMargin
Link copied to clipboard
val rootMargin : String

An offset rectangle applied to the root's bounding box when calculating intersections, effectively shrinking or growing the root for calculation purposes. The value returned by this property may not be the same as the one specified when calling the constructor as it may be changed to match internal requirements. Each offset can be expressed in pixels (px) or as a percentage (%). The default is "0px 0px 0px 0px".

thresholds
Link copied to clipboard
val thresholds : Array < Number >

A list of thresholds, sorted in increasing numeric order, where each threshold is a ratio of intersection area to bounding box area of an observed target. Notifications for a target are generated when any of the thresholds are crossed for that target. If no value was passed to the constructor, 0 is used.

## Functions

disconnect
Link copied to clipboard
fun disconnect ()

Stops the IntersectionObserver object from observing any target.

observe
Link copied to clipboard
fun observe (targetElement: Element )

Tells the IntersectionObserver a target element to observe.

takeRecords
Link copied to clipboard
fun takeRecords (): Array < IntersectionObserverEntry >

Returns an array of IntersectionObserverEntry objects for all observed targets.

unobserve
Link copied to clipboard
fun unobserve (targetElement: Element )

Tells the IntersectionObserver to stop observing a particular target element.