-
-
Save anam-hossain/7a10734514a9c53d88a8 to your computer and use it in GitHub Desktop.
<html> | |
<head> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css"> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> | |
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script> | |
<script> | |
$(function() { | |
$(".video").click(function () { | |
var theModal = $(this).data("target"), | |
videoSRC = $(this).attr("data-video"), | |
videoSRCauto = videoSRC + "?modestbranding=1&rel=0&controls=0&showinfo=0&html5=1&autoplay=1"; | |
$(theModal + ' iframe').attr('src', videoSRCauto); | |
$(theModal + ' button.close').click(function () { | |
$(theModal + ' iframe').attr('src', videoSRC); | |
}); | |
}); | |
}); | |
</script> | |
</head> | |
<body> | |
<button class="btn btn-success btn-lg video" data-video="https://www.youtube.com/embed/8L5PqL4ylIU" data-toggle="modal" data-target="#videoModal">Play Video 1</button> | |
<button class="btn btn-default btn-lg video" data-video="https://www.youtube.com/embed/HBdcL7YsdBY" data-toggle="modal" data-target="#videoModal">Play Video 2</button> | |
<div class="modal fade" id="videoModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> | |
<div class="modal-dialog"> | |
<div class="modal-content"> | |
<div class="modal-body"> | |
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> | |
<iframe width="100%" height="350" src="" frameborder="0" allowfullscreen></iframe> | |
</div> | |
</div> | |
</div> | |
</div> | |
</body> | |
</html> |
Thanks for sharing this nice and simple code. @jeremydanielfox I guess you are talking about closing video. There is an event http://getbootstrap.com/javascript/#modals-events
$('#myModal').on('hidden.bs.modal', function (e) { // do something... })
I have ended up like this;
<button class="btn btn-success btn-lg video" data-video="https://www.youtube.com/embed/lZX8jeTvxOY" data-toggle="modal" data-target="#videoModal">Play Video 1</button>
<div class="modal fade" id="videoModal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-body">
<div class="embed-responsive embed-responsive-16by9">
<iframe width="100%" height="500" src="" frameborder="0" allowfullscreen></iframe>
</div>
</div>
</div>
</div>
</div>
$(function() {
$(".video").click(function () {
var theModal = $(this).data("target"),
videoSRC = $(this).attr("data-video"),
videoSRCauto = videoSRC;
$(theModal + ' iframe').attr('src', videoSRCauto);
$(theModal + ' button.close').click(function () {
$(theModal + ' iframe').attr('src', '');
});
});
});
$('#videoModal').on('hidden.bs.modal', function (e) {
$('#videoModal').find('iframe').attr('src', '');
});
This works perfect, Thanks!
Here's a good example and work, he helped me.
http://www.tutorialrepublic.com/faq/how-to-embed-youtube-video-inside-bootstrap-modal.php
Just wondering if there was a way to put a close button within the modal popup that contains the video. Right now mine only closes if you click the border around the video
@jeremydanielfox, To stop video (remove iframe src) on clicking outside of modal (dismiss) the following should work.
replace:
$(theModal + ' button.close').click(function () {
with:
$(theModal).on('click', function(){
This worked well thanks for sharing
This works brilliantly for me on Chrome, Firefox etc but not on Safari (although it is ok on iphone).
On Safari the modal opens with a blurred image where the video is, and then nothing happens.
Does any one have any ideas how I could solve this?
Thank you so much, it helps me lot!!
but guys can anybody make popup video like this, here you can see - popup video of adobe photoshop - https://www.adobe.com/in/products/photoshop.html
This helped me a lot, thank you! Do you know why if I modify the CSS of the buttons with my own CSS the whole function stops working? Is there another way to modify the design of the buttons? Thank you!
This just helped me figure out my issue. Thanks a lot!
La rompiste me funciono perfectamente
This saved my butt! Thank you!!!!
Hello for always launch autoplay
replace <iframe width="100%" height="350" src="" frameborder="0" allowfullscreen></iframe>
by
Thanks
well done
Not working in Mobile can anyone tell me the solution.
Hi -- thanks for the code -- it works very well! I'm wondering -- how can I make the modal close when a user clicks outside of it?
Thanks!