IntersectionObserver is used to 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.
IntersectionObserver.relativeTo()
Specify the reference node, which is specified based on id.
IntersectionObserver.relativeToViewport()
Specify LynxView as the reference node.
IntersectionObserver.relativeToScreen()
Specify the screen as the reference node.
IntersectionObserver.observer()
Specify the target node and callback. The target node is specified based on id.
IntersectionObserver.disconnect()
Clear the target node and callback, the target node will no longer be observed, and the corresponding callback will not be triggered.
You can observe changes in the intersection status of the target node and the reference node through the following three steps:
IntersectionObserver object and specify a threshold list for intersection state changesrelativeTo* method of the IntersectionObserver object to specify the reference nodeobserve method of the IntersectionObserver object to specify the target node and callbackdisconnect method of the IntersectionObserver object to clear the target node and callbackenableNewIntersectionObserver to true, otherwise the scrollable container needs to be bound to the corresponding scroll event (such as scroll) to trigger the corresponding callback.relativeTo and observe methods, you need to pay attention to the calling timing and ensure that the reference node and target node have been created when calling. Otherwise, the observation will be invalid, that is, the corresponding callback will never be triggered.LCD tables only load in the browser