IntersectionObserver
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.
Instance method
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.
Example
You can observe changes in the intersection status of the target node and the reference node through the following three steps:
- Create an
IntersectionObserverobject and specify a threshold list for intersection state changes - Call the
relativeTo*method of theIntersectionObserverobject to specify the reference node - Call the
observemethod of theIntersectionObserverobject to specify the target node and callback - Call the
disconnectmethod of theIntersectionObserverobject to clear the target node and callback
Precautions
- It is recommended to set the page switch
enableNewIntersectionObservertotrue, otherwise the scrollable container needs to be bound to the corresponding scroll event (such asscroll) to trigger the corresponding callback. - When using
relativeToandobservemethods, 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.
Compatibility
LCD tables only load in the browser