Rui Farinha Rui Farinha - 1 year ago 93
HTML Question

Load and shuffle videos each time you enter site

I've been using this boostrap snippet that loads a video when entering site.

I'm trying to make it load and randomize a list of videos each time you enter the site, but I'm not getting it to work. Help me pls!


<section class="content-section video-section"><div class="pattern-overlay"><a id="bgndVideo" class="player" data-property="{videoURL:'',containment:'.video-section', quality:'large', autoPlay:true, mute:true, opacity:1}">bg</a></div></section>


$(document).ready(function () {

$(".player").mb_YTPlayer(); });

Best Reagrds.

Answer Source

I would keep an array of the video URL's, as well as the various options for the video, then select one video at random when the page is loaded and update the data-property of the html.


var vids = ["",
  ""]; // create your list of youtube videos

var currVid = vids[Math.floor(Math.random()*(vids.length-1))]; // this will grab a random video from the array.

var opts = { // keep all the options in an object
  videoURL: currVid, // set the video to display

  document.getElementById("bgndVideo") = JSON.stringify(opts); // change to this

  $(".player").mb_YTPlayer(); // play!

Hopefully this helps!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download