Interface Visibility

The visibility API.

interface Visibility {
    ratio: number;
    visible: boolean;
    visibleThreshold: number;
    addObserver(step, callback): VisibilityObserver;
    removeObserver(observer): void;


ratio: number

The ratio of pixels of the player that are within the viewport.

visible: boolean

Whether the Visibility.ratio of visible pixels is exceeded.

visibleThreshold: number

The threshold that the ratio must exceed for the player to be visible.


- This number is in the range of [0, 1].


  • Add a visibility observer to monitor the player.


    • step: number

      The step between every threshold. This number is in the range of ]0, 1].

    • callback: VisibilityObserverCallback

      The callback to be triggered every time a threshold is crossed.

    Returns VisibilityObserver

    A new visibility observer.


    - The callback is triggered every time the ratio of visible pixels crosses a threshold, and receives the ratio of visible pixels as first argument.
    - The list of thresholds is evenly distributed between 0 and 1, with the distance between every two consecutive thresholds determined by the given step.

  • Remove a visibility observer.

    The observer will stop monitoring player visibility, and will no longer trigger its callback.


    Returns void