IntersectionObserverEntry: IntersectionObserverEntry() constructor

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

The IntersectionObserverEntry() constructor creates and returns a new IntersectionObserverEntry object.

Note: In typical usage, you don't need to call this constructor yourself. IntersectionObserverEntry objects are created automatically by the browser and delivered to the IntersectionObserver callback when an intersection is observed, or returned by IntersectionObserver.takeRecords().

Syntax

js
new IntersectionObserverEntry(intersectionObserverEntryInit)

Parameters

intersectionObserverEntryInit

An object with the following properties, all of which are required:

boundingClientRect

An object specifying the location and dimensions of the target element's bounding rectangle, with x, y, width, and height properties. This corresponds to the rectangle returned by Element.getBoundingClientRect().

intersectionRatio

A number representing the ratio of the intersectionRect area to the boundingClientRect area. If the boundingClientRect area is zero, this is 1 if isIntersecting is true, and 0 if not.

intersectionRect

An object specifying the location and dimensions of the target's visible area within the root's intersection rectangle, with x, y, width, and height properties.

isIntersecting

A boolean value which is true if the target element intersects with the intersection observer's root, or false otherwise.

isVisible

A boolean value which is true if the target element has been determined to be fully visible and unoccluded, with no visual effects that would alter its display on screen. A value of false means either that the target has compromised visibility, or that this determination could not be made.

rootBounds

An object specifying the location and dimensions of the root's intersection rectangle, with x, y, width, and height properties, or null.

target

The Element whose intersection with the root changed.

time

A DOMHighResTimeStamp indicating the time at which the intersection was recorded, relative to the IntersectionObserver's time origin.

Return value

A new IntersectionObserverEntry object whose properties are initialized to the values specified in intersectionObserverEntryInit.

Examples

Creating an IntersectionObserverEntry

This example creates a basic IntersectionObserverEntry describing a fully visible element. While you can construct an entry manually like this, in practice these objects are created by the browser and passed to your IntersectionObserver callback automatically.

js
const entry = new IntersectionObserverEntry({
  time: performance.now(),
  rootBounds: { x: 0, y: 0, width: 1024, height: 768 },
  boundingClientRect: { x: 10, y: 20, width: 200, height: 100 },
  intersectionRect: { x: 10, y: 20, width: 200, height: 100 },
  isIntersecting: true,
  isVisible: false,
  intersectionRatio: 1.0,
  target: document.body,
});

Specifications

Specification
Intersection Observer
# dom-intersectionobserverentry-intersectionobserverentry

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
IntersectionObserverEntry() constructor
Experimental
Chrome – No support
Chrome
footnote No support
Edge – No support
Edge 15 – 18 (Release date: 2017-04-05)
footnote Removed in 79 and later
Firefox – No support
Firefox
footnote No support
Opera – No support
Opera
footnote No support
Safari – Full support
Safari 12.1 (Release date: 2019-03-25)
footnote Full support
Chrome Android – No support
Chrome Android
footnote No support
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – No support
Opera Android
footnote No support
Safari on iOS – Full support
Safari on iOS 12.2 (Release date: 2019-03-25)
footnote Full support
Samsung Internet – No support
Samsung Internet
footnote No support
WebView Android – No support
WebView Android
footnote No support
WebView on iOS – Full support
WebView on iOS 12.2 (Release date: 2019-03-25)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
Experimental. Expect behavior to change in the future.

See also