THEOplayer > Visibility
The visibility API.
Signature:
export interface Visibility
Property |
Type |
Description |
---|---|---|
|
The ratio of pixels of the player that are within the viewport. |
|
|
Whether the Visibility.ratio of visible pixels is exceeded. |
|
|
The threshold that the ratio must exceed for the player to be visible. |
Method |
Description |
---|---|
addObserver(step: |
Add a visibility observer to monitor the player. |
removeObserver(observer: VisibilityObserver): |
Remove a visibility observer. The observer will stop monitoring player visibility, and will no longer trigger its callback. |
The ratio of pixels of the player that are within the viewport.
Signature:
readonly ratio: number;
Whether the Visibility.ratio of visible pixels is exceeded.
Signature:
readonly visible: boolean;
The threshold that the ratio must exceed for the player to be visible.
Signature:
visibleThreshold: number;
- This number is in the range of [0, 1].
Add a visibility observer to monitor the player.
Signature:
addObserver(step: number, callback: VisibilityObserverCallback): VisibilityObserver;
Parameter |
Type |
Description |
---|---|---|
step |
|
The step between every threshold. This number is in the range of ]0, 1]. |
callback |
The callback to be triggered every time a threshold is crossed. |
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.
Signature:
removeObserver(observer: VisibilityObserver): void;
Parameter |
Type |
Description |
---|---|---|
observer |
The observer to remove. |