Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grand-lotus-iroh/57ff9588355301ce1c35cc5c0479b754 to your computer and use it in GitHub Desktop.
Save grand-lotus-iroh/57ff9588355301ce1c35cc5c0479b754 to your computer and use it in GitHub Desktop.
Autoplay HTML5 Video with Modal and Keyboard Support
<script type="text/javascript">
$('#modal-sample').on('shown.bs.modal', function() {
$('#video1')[0].play();
})
$('#modal-sample').on('hidden.bs.modal', function() {
$('#video1')[0].pause();
})
$(window).keypress(function(e) {
var video = document.getElementById("video1");
if (e.which == 32) {
if (video.paused == true) video.play();
else video.pause();
}
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment