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/lynx/lynx-create-intersection-observer.md.
Lynx
  • English
  • lynx: createIntersectionObserver() static method

    lynx.createIntersectionObserver() creates an IntersectionObserver. Use options to control when callbacks run.

    grammar

    createIntersectionObserver(
      component: { componentId: string },
      options?: {
        thresholds?: number[];
        initialRatio?: number;
        observeAll?: boolean;
      },
    ): IntersectionObserver;

    Parameters

    component

    Pass { componentId: '' } to find the target and reference nodes in the current LynxView. With a component ID, Lynx searches that component first and falls back to the whole LynxView if needed.

    options

    • thresholds is a list of intersection ratios in [0, 1]. The default is [0]. After the first check, a callback runs when the ratio reaches, leaves, or crosses a threshold.
    • initialRatio sets the baseline for the first check. It ranges from 0 to 1 and defaults to 0. By default, the first check triggers the callback only if the ratio is greater than initialRatio. When enableIntersectionObserverInitialRatioCompatibility is enabled (available since Lynx 4.5), the first ratio must differ from initialRatio and meet or exceed at least one configured threshold.
    • observeAll is reserved on Android, iOS, and Harmony. The default is false.

    return value

    An IntersectionObserver object.

    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.

    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.