Skip to content
This repository has been archived by the owner on Jun 18, 2020. It is now read-only.

Latest commit

 

History

History
56 lines (44 loc) · 1.26 KB

README.md

File metadata and controls

56 lines (44 loc) · 1.26 KB

VideoJS Viewability

VideoJS Viewability script, allows to handle viewability for multiple videos

Demo 1

Viewability Demo 1

Demo 2

Viewability Demo 2

Usage

Step 1

Add script to your page

<script type="text/javascript" src="viewability.js"></script>

Step 2

  • Create a array to hold players that init
  • Push every player objects to players array
var players = [] // Create a array to hold players that init
function initPlayer (id) {
  /* Your Player Configuration */
  window[`quark-${id}`] = new videojs(`#${id}`, {
    techOrder: ['html5'],
    'autoplay': false
  });
  
  window[`quark-${id}`].src({
    src: 'sample.mp4',
    type: 'video/mp4'
  });

  /* Push player objects to players array on every init
     to handle viewability between each other */
  players.push(window[`quark-${id}`])
}

/* Init players */
initPlayer('player-1')
initPlayer('player-2')
initPlayer('player-3')

Step 3

Create new Viewability instance with players array

/* Init Viewability */
var viewability = new Viewability({
  players: players
})