Last active
January 4, 2016 18:49
-
-
Save alexmahan/8663168 to your computer and use it in GitHub Desktop.
Loops through a bunch of videos (however many you want) and plays them infinitely. You can set the first one to "autoplay" in the markup if you wish. This uses jQuery but could be (should be) vanilla JavaScript easily enough. Doesn't work in IE8 or under (duh) because it uses addEventListener and uses the <video> element with no flash fallback.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vidLooper = function() { | |
var allVids = $('.vid'); | |
$.each(allVids, function(index, value) { | |
if (index < allVids.length-1) { | |
value.addEventListener('ended', function() { | |
var nextVid = allVids.eq(index+1); | |
nextVid[0].play(); | |
}); | |
} else if (index === allVids.length-1) { | |
value.addEventListener('ended', function() { | |
var firstVid = allVids[0]; | |
firstVid.play(); | |
}); | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment