For AI agents: the complete documentation index is available at /next/llms.txt, the full documentation bundle is available at /next/llms-full.txt, and this page is available as Markdown at /next/api/lynx-api/intersection-observer.md.
Lynx
  • English
  • IntersectionObserver BTS

    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()

    Select the reference node with a #id selector.

    IntersectionObserver.relativeToViewport()

    Use the LynxView viewport as the reference area.

    IntersectionObserver.relativeToScreen()

    Use the screen as the reference area.

    IntersectionObserver.observe()

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

    IntersectionObserver.disconnect()

    Stop observing all target nodes.

    Example

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

    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 to false on the child node to trigger them.

    Compatibility

    LCD tables only load in the browser

    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.