Created
July 2, 2015 13:10
-
-
Save johnmurch/914dfc9ee3c8429fbe2f to your computer and use it in GitHub Desktop.
Bootstrap Video Modal via http://stackoverflow.com/questions/18622508/bootstrap-3-and-youtube-in-modal
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
$(document).ready(function(){ | |
autoPlayYouTubeModal(); | |
}); |
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
//FUNCTION TO GET AND AUTO PLAY YOUTUBE VIDEO FROM DATATAG | |
function autoPlayYouTubeModal(){ | |
var trigger = $("body").find('[data-toggle="modal"]'); | |
trigger.click(function() { | |
var theModal = $(this).data( "target" ), | |
videoSRC = $(this).attr( "data-theVideo" ), | |
videoSRCauto = videoSRC+"?autoplay=1" ; | |
$(theModal+' iframe').attr('src', videoSRCauto); | |
$(theModal+' button.close').click(function () { | |
$(theModal+' iframe').attr('src', videoSRC); | |
}); | |
}); | |
} |
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
<a href="#" class="btn btn-default" data-toggle="modal" data-target="#videoModal" data-theVideo="http://www.youtube.com/embed/loFtozxZG0s" >VIDEO</a> |
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
<div class="modal fade" id="videoModal" tabindex="-1" role="dialog" aria-labelledby="videoModal" aria-hidden="true"> | |
<div class="modal-dialog"> | |
<div class="modal-content"> | |
<div class="modal-body"> | |
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> | |
<div> | |
<iframe width="100%" height="350" src=""></iframe> | |
</div> | |
</div> | |
</div> | |
</div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment