Skip to content

Instantly share code, notes, and snippets.

@justkabin
Forked from gerbenvandijk/dynamicvideo.js
Created August 7, 2018 12:16
Show Gist options
  • Select an option

  • Save justkabin/abbc53d4b4238c4ce5cb0791e7cc346a to your computer and use it in GitHub Desktop.

Select an option

Save justkabin/abbc53d4b4238c4ce5cb0791e7cc346a to your computer and use it in GitHub Desktop.
Dynamically loading a HTML5 video element with JavaScript
function loadVid(){
var videourl = 'urltoyourvideo here'; // set the url to your video file here
var videocontainer = '#videocontainer'; // set the ID of the container that you want to insert the video in
var parameter = new Date().getMilliseconds(); // generate variable based on current date/time
var video = '<video width="1102" height="720" id="intro-video" autoplay loop src="' + videourl + '?t=' + parameter + '"></video>'; // setup the video element
$(videocontainer).append(video); // insert the video element into its container
videl = $(document).find('#intro-video')[0]; // find the newly inserterd video
videl.load(); // load the video (it will autoplay because we've set it as a parameter of the video)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment