logo

THEOplayer > Visibility

Visibility interface

The visibility API.

Signature:

export interface Visibility 

Properties

Property

Type

Description

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.

Methods

Method

Description

addObserver​(step: number, callback: VisibilityObserverCallback): VisibilityObserver

Add a visibility observer to monitor the player.

removeObserver​(observer: VisibilityObserver): void

Remove a visibility observer.

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

Property Details

ratio

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

Signature:

readonly ratio: number;

visible

Whether the Visibility.ratio of visible pixels is exceeded.

Signature:

readonly visible: boolean;

visibleThreshold

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

Signature:

visibleThreshold: number;

Remarks


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

Method Details

addObserver

Add a visibility observer to monitor the player.

Signature:

addObserver(step: number, callback: VisibilityObserverCallback): VisibilityObserver;

Parameters

Parameter

Type

Description

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

A new visibility observer.

Remarks


- 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.

removeObserver

Remove a visibility observer.

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

Signature:

removeObserver(observer: VisibilityObserver): void;

Parameters

Parameter

Type

Description

observer

VisibilityObserver

The observer to remove.

github
Make sure to follow us on GitHub!
THEO-logo-white
twitter
facebook
linkedin
Copyright © 2020. All Rights Reserved.
Leuven
New York
San Francisco
Singapore
Barcelona