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:
lynx.createIntersectionObserver
to create an IntersectionObserver
object and specify the threshold list of intersection status changes.relativeTo
method of the IntersectionObserver
object to specify the reference node.observe
method of the IntersectionObserver
object to specify the target node and callback.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
.