> For AI agents: the complete documentation index is available at /next/llms.txt, the full documentation bundle is available at /next/llms-full.txt.

# IntersectionObserver

APISummary
`IntersectionObserver` tracks how a target node intersects a reference area, accounting for clipping by ancestor nodes. Use it to detect when a node becomes visible or leaves the visible area.

## Instance method

[`IntersectionObserver.relativeTo()`](/next/api/lynx-api/intersection-observer/intersection-observer-relative-to.md)

Select the reference node with a `#id` selector.

[`IntersectionObserver.relativeToViewport()`](/next/api/lynx-api/intersection-observer/intersection-observer-relative-to-viewport.md)

Use the `LynxView` viewport as the reference area.

[`IntersectionObserver.relativeToScreen()`](/next/api/lynx-api/intersection-observer/intersection-observer-relative-to-screen.md)

Use the screen as the reference area.

[`IntersectionObserver.observe()`](/next/api/lynx-api/intersection-observer/intersection-observer-observe.md)

Select the target node with a `#id` selector and register a callback.

[`IntersectionObserver.disconnect()`](/next/api/lynx-api/intersection-observer/intersection-observer-disconnect.md)

Stop observing all target nodes.

## Example

This example observes how `#targetNode` intersects `#refNode` in the current `LynxView`.

```tsx
const observer = lynx.createIntersectionObserver(
  { componentId: '' },
  { thresholds: [0, 0.25, 0.5, 0.75, 1] },
);

observer.relativeTo('#refNode', { left: 10, right: 10 });
observer.observe('#targetNode', (entry) => {
  console.log(entry.intersectionRatio);
});
```

Call `observer.disconnect()` when you no longer need to observe the target.

## Precautions

- Call `relativeTo()` and `observe()` after the reference and target nodes have been created.
- On Android, child nodes of a horizontally scrolling `scroll-view` do not trigger callbacks while scrolling. Set [`flatten`](/next/api/elements/built-in/view.md#flatten) to `false` on the child node to trigger them.

## Compatibility

**Compatibility Table**

**Query:** `lynx-api.intersection-observer.IntersectionObserver`

[Source](https://github.com/lynx-family/lynx-website/tree/main/packages/lynx-compat-data/lynx-api/intersection-observer/IntersectionObserver.json)

| Feature | Android | HarmonyOS | iOS | macOS | Windows | Web |
| --- | --- | --- | --- | --- | --- | --- |
| IntersectionObserver | Yes (1.5) | Yes (3.4) | Yes (1.5) | Yes (3.5) | Yes (3.5) | Yes |
| relativeTo | Yes (1.5) | Yes (3.4) | Yes (1.5) | Yes (3.5) | Yes (3.5) | Yes |
| relativeToViewport | Yes (1.5) | Yes (3.4) | Yes (1.5) | Yes (3.5) | Yes (3.5) | Yes |
| relativeToScreen | Yes (2.10) | Yes (3.4) | Yes (2.10) | Yes (3.5) | Yes (3.5) | Yes |
| observe | Yes (1.5) | Yes (3.4) | Yes (1.5) | Yes (3.5) | Yes (3.5) | Yes |
| disconnect | Yes (1.5) | Yes (3.4) | Yes (1.5) | Yes (3.5) | Yes (3.5) | Yes |

**`IntersectionObserver`**

Observe the intersection status between the target node and the reference node and the target node and the ancestor node. When the intersection status changes, the corresponding callback is triggered. Based on this, you can monitor whether the target node is exposed/de-exposed.

**`relativeTo`**

Specify a reference node. The reference node is specified by id.

[Source](https://github.com/lynx-family/lynx-website/tree/main/packages/lynx-compat-data/lynx-api/intersection-observer/IntersectionObserver.json) · [API Reference](/next/api/lynx-api/intersection-observer/intersection-observer-relative-to)

**`relativeToViewport`**

Specify a LynxView as a reference node.

[Source](https://github.com/lynx-family/lynx-website/tree/main/packages/lynx-compat-data/lynx-api/intersection-observer/IntersectionObserver.json) · [API Reference](/next/api/lynx-api/intersection-observer/intersection-observer-relative-to-viewport)

**`relativeToScreen`**

Specify the screen as the reference node.

[Source](https://github.com/lynx-family/lynx-website/tree/main/packages/lynx-compat-data/lynx-api/intersection-observer/IntersectionObserver.json) · [API Reference](/next/api/lynx-api/intersection-observer/intersection-observer-relative-to-screen)

**`observe`**

Specify the target node and callback, and the target node is specified according to id.

[Source](https://github.com/lynx-family/lynx-website/tree/main/packages/lynx-compat-data/lynx-api/intersection-observer/IntersectionObserver.json) · [API Reference](/next/api/lynx-api/intersection-observer/intersection-observer-observe)

**`disconnect`**

Clear the target node and callback. The target node will no longer be observed and the corresponding callback will not be triggered.

[Source](https://github.com/lynx-family/lynx-website/tree/main/packages/lynx-compat-data/lynx-api/intersection-observer/IntersectionObserver.json) · [API Reference](/next/api/lynx-api/intersection-observer/intersection-observer-disconnect)

