Intersection Observer

The intersection observer provides a method to observe the intersection status between the target node and the reference node and between the target node and the ancestor node. When the intersection status changes, the corresponding callback is triggered.

Developers can observe the changes in the intersection status between the target node and the reference node through the following three steps:

  1. Call lynx.createIntersectionObserver to create an IntersectionObserver object and specify the threshold list of intersection status changes.
  2. Call the relativeTo method of the IntersectionObserver object to specify the reference node.
  3. Call the observe method of the IntersectionObserver object to specify the target node and callback.
  4. Call the disconnect method of the IntersectionObserver object to clear the target node and callback.

In the following example, the developer monitors whether the parent node and the child node intersect, and outputs the intersecting child node id and the intersection position when they intersect.

For the specific syntax of the intersection observer, please refer to IntersectionObserver.

Except as otherwise noted, this work is licensed under a Creative Commons Attribution 4.0 International License, and code samples are licensed under the Apache License 2.0.