Visibility API
The Visibility API provides developers a way to observe how much of the player is visible.
Properties
The visibility
object provides the following properties:
Property | Type | Description |
---|---|---|
visible | boolean | Indicates whether or not the ratio of visible pixels of the player exceeds the visible threshold. |
ratio | number | Indicates the ratio of pixels of the player that are within the viewport. |
visibleThreshold | number | Gets or sets the threshold that the ratio must exceed for the player to be visible. |
Methods
The visibility
object provides the following methods:
Property | Type | Description |
---|---|---|
addObserver | step : number, callback : function |
Adds an observer to monitor the visibility of the player, and returns the created VisibilityObserver. 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 | observer : VisibilityObserver | Removes a previously created visibility observer. |
VisibilityObserver
The VisibilityObserver
API enables you to access the thresholds and ratio of a visibility observer.
Properties
The VisibilityObserver
object provides the following properties:
Property | Type | Description |
---|---|---|
ratio | number | The ratio of pixels of the player that are within the viewport. |
thresholds | number[] | The list of thresholds which are monitored by this observer. |