jq-video-layers players

jqVideoLayers is a JQuery widget that allows to add layers like Youtube to any html5 video. Could be used with other javascript players

by Haztivity

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.structure.min.css">
<script src="https://cdn.rawgit.com/davinchi-finsi/jq-video-layers/6ca118bd/dist/jquery.video-layers.min.js"></script>
<link rel="stylesheet" href="https://cdn.rawgit.com/davinchi-finsi/jq-video-layers/6ca118bd/dist/video-layers.structure.css">
<link rel="stylesheet" href="https://cdn.rawgit.com/davinchi-finsi/jq-video-layers/6ca118bd/dist/video-layers.theme-default.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/plyr/2.0.18/plyr.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/plyr/2.0.18/plyr.css">
<p>Try the video in fullscreen!</p>
<div class="main">
  <video width="400" controls>
     <source src="https://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4">
     <source src="https://www.w3schools.com/html/mov_bbb.ogg" type="video/ogg">
     Your browser does not support HTML5 video.
   </video>
  <div>
    <div id="external-layer-1" class="layer">
      First Layer in other container
    </div>
    <div id="external-layer-2" class="layer">
      Second Layer in other container
    </div>
  </div>
</div>
<div id="layer-img" class="layer">
  <img src="http://maxpixel.freegreatpicture.com/static/photo/1x/Nature-Summer-Tree-Sea-Grass-Sun-Ocean-Landscape-2435269.jpg">
</div>
<ul clas="log">
</ul>
</div>

CSS

.layer {
  display: none;
}

.main {
  display: flex;
}

.main>* {
  flex-basis: 50%;
  margin: 0 1em;
}

JavaScript

//Init plyr video player
plyr.setup();

let $log = $(".log");
$("video").videoLayers({
  //set the plyr container as wrapper container
  useParentAsContainer: ".plyr__video-wrapper",
  layers: [{
      //id is not an layer option, but any property could be added and retrieved in the events
      id: "layer-1",
      content: "Some text",
      position: [25, 25],
      start: 1,
      stop: 4,
      //Add the properties you desire
      myCustomProperty: "myCustomValue"
    },
    {
      id: "layer-2",
      element: "#external-layer-1",
      appendToLayers: false, //by default the layers are appended to the layer container
      start: 1,
      stop: 4,
      show: {
        effect: "fade",
        duration: 1000
      },
      hide: {
        effect: "fade",
        duration: 1000
      }
    },
    {
      id: "layer-3",
      element: "#layer-img",
      cssClass: "addThisClass andThisOne c-video-layers__layer--strip",
      styles: {
        width: "50%"
      },
      position: {
        my: "center",
        to: "center"
      },
      start: 5,
      stop: 10,
      show: {
        effect: "fade",
        duration: 1000
      },
      hide: {
        effect: "blind",
        duration: 500
      }
    },
    {
      id: "layer-4",
      element: "#external-layer-2",
      appendToLayers: false, //by default the layers are appended to the layer container
      start: 5,
      stop: 10,
      show: {
        effect: "fade",
        duration: 1000
      },
      hide: {
        effect: "fade",
        duration: 1000
      }
    }
  ]
}).on(jqVideoLayers.VideoLayersEvents.beforeShowLayer, (e, data) => {
  $log.append(`beforeShow layer: ${data.layer.id}`);
  console.log("beforeShow", data.layer);
}).on(jqVideoLayers.VideoLayersEvents.showLayer, (e, data) => {
  $log.append(`showLayer layer: ${data.layer.id}`);
}).on(jqVideoLayers.VideoLayersEvents.beforeHideLayer, (e, data) => {
  $log.append(`beforeHideLayer layer: ${data.layer.id}`);
 ...