CodePen
codepen.io โบ mattamyot โบ pen โบ dMGwyK
YouTube Video Modal
</p> </article> </section> </main> <!-- video modal --> <section class="video-modal"> <!-- Modal Content Wrapper --> <div id="video-modal-content" class="video-modal-content" > <!-- iframe --> <iframe id="youtube" width="100%" height="100%" frameborder="0" allow="autoplay" allowfullscreen src= ></iframe> <a href="#" class="close-video-modal" > <!-- X close video icon --> <svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0" y="0" viewBox="0 0 32 32" style="enable-background:new 0 0 32 32;" xml:space="preserve" width="24" height="24" > <g id="ico
CodePen
codepen.io โบ deeppines โบ pen โบ KgvGpN
Youtube video on modal popup.
var player; var lastButton = ''; const youtube = 'youTubeIframe'; const titleInsert = '.js-title-insert'; const btnPlay = '.js-play'; const btnPause = '.js-pause'; const modalId = '#modalVideo'; const videoQuality = 'hd720'; function onYouTubePlayerAPIReady() { player = new YT.Player(youtube, { controls: 2, iv_load_policy: 3, rel: 0, events: { onReady: onPlayerReady } }); } function onPlayerReady(event) { 'use strict'; $(btnPlay).on('click', function() { var videoId = $(this).attr('data-src'); if (lastButton == videoId) { $(titleInsert).text($(this).attr('data-title')); player.playVideo(videoId, 0, videoQuality); } else { $(titleInsert).text($(this).attr('data-title')); player.loadVideoById(videoId, 0, videoQuality); lastButton = videoId; } }); $(btnPause).on('click', function() { player.pauseVideo(); }); $(modalId).on('click', function() { player.pauseVideo(); }); }
Videos
04:16
Simple Modal Window or Popup Using HTML / CSS Only - YouTube
40:18
Modal with HTML, CSS and JavaScript - YouTube
31:27
Create a Modal With HTML, CSS & JavaScript - YouTube
09:40
dialog = the easiest way to make a popup modal - YouTube
14:47
How to create Modal Popup Window in JavaScript - Tutorial with ...
10:01
Create a Modal (Popup) with HTML/CSS and JavaScript - YouTube
CodePen
codepen.io โบ tkshamseer โบ pen โบ rvWVrZ
YOUTUBE/VIMEO VIDEO ON BOOTSTRAP MODAL POPUP
<a href="#" class="video-btn" data-toggle="modal" data-src="https://www.youtube.com/embed/immbOqvDLYY" data-target="#video_pop">Watch Video</a> <!-- POPUP --> <div class="modal fade" id="video_pop" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true"> <div class="modal-dialog" role="document"> <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> <!-- 16:9 aspect ratio --> <div class="embed-responsive embed-responsive-16by9"> <iframe class="embed-responsive-item" src="" id="video" allowscriptaccess="always"></iframe> </div> </div> </div> </div> </div>
CodePen
codepen.io โบ captain_yar โบ pen โบ OJMEmGw
Popup modal with YouTube video (YouTube API)
var tag = document.createElement("script"); tag.src = "https://www.youtube.com/iframe_api"; var firstScriptTag = document.getElementsByTagName("script")[0]; firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); // Get video ID var vidId = document.getElementById("player").dataset.id; // Build the player var player; function onYouTubeIframeAPIReady() { player = new YT.Player("player", { height: "390", width: "640", videoId: vidId, events: { onReady: onPlayerReady } }); } // ==== Variables for popup var modal = document.querySelector(".modal"), close = document.querySelector(".close-modal
CodePen
codepen.io โบ netteria โบ pen โบ dLWxJJ
Responsive Youtube modal video. Popup video
<a href="javascript:void(0)" id="video1">-- open video --</a> <div id="vidBox"> <div id="videCont"> <div id="yt_video"> <iframe id="v1" allowfullscreen="" frameborder="0" src="https://www.youtube.com/embed/JjtRj5ybloY"></iframe> </div> </div> </div> <br /><br /><br /><br /> GitHub - <a href="https://github.com/netteria/html5-video-popup-responsive" target="_blank">HTML5 responsive popup video by Netteria.NET</a>
CodePen
codepen.io โบ lucaskane โบ embed โบ KgvGpN
CodePen Embed - Youtube video on modal popup.
var player; var lastButton = ''; const youtube = 'youTubeIframe'; const titleInsert = '.js-title-insert'; const btnPlay = '.js-play'; const btnPause = '.js-pause'; const modalId = '#modalVideo'; const videoQuality = 'hd720'; function onYouTubePlayerAPIReady() { player = new YT.Player(youtube, { controls: 2, iv_load_policy: 3, rel: 0, events: { onReady: onPlayerReady } }); } function onPlayerReady(event) { 'use strict'; $(btnPlay).on('click', function() { var videoId = $(this).attr('data-src'); if (lastButton == videoId) { $(titleInsert).text($(this).attr('data-title')); player.playVideo(videoId, 0, videoQuality); } else { $(titleInsert).text($(this).attr('data-title')); player.loadVideoById(videoId, 0, videoQuality); lastButton = videoId; } }); $(btnPause).on('click', function() { player.pauseVideo(); }); $(modalId).on('click', function() { player.pauseVideo(); }); }
CodePen
codepen.io โบ JacobLett โบ pen โบ xqpEYE
Play YouTube or Vimeo Video in Modal - Bootstrap 4
<div class="container"> <h1>Play YouTube or Vimeo Videos in Bootstrap 4 Modal</h1> <!-- Button trigger modal --> <button type="button" class="btn btn-primary video-btn" data-toggle="modal" data-src="https://www.youtube.com/embed/NFWSFbqL0A0" data-target="#myModal"> Play Video 1 - autoplay </button> <!-- Button trigger modal --> <button type="button" class="btn btn-primary video-btn" data-toggle="modal" data-src="https://www.youtube.com/embed/JJUo8Fe3_JY" data-target="#myModal"> Play Video 2 </button> <!-- Button trigger modal --> <button type="button" class="btn btn-primary video-btn" data-tog
CodePen
codepen.io โบ raaasin โบ pen โบ YGOKRy
Video Modal Box
<a class="popup-youtube" href="https://www.youtube.com/watch?v=TuoNvPPnr2o">Open YouTube video</a> <script> $(document).ready(function() { $('.popup-youtube, .popup-vimeo, .popup-gmaps').magnificPopup({ disableOn: 700, type: 'iframe', mainClass: 'mfp-fade', removalDelay: 160, preloader: false, fixedContentPos: false }); }); </script>
CodePen
codepen.io โบ 25virus โบ embed โบ BaozeOq
CodePen Embed - Youtube Video on Bootstrap Modal Popup with Fency Play Button
<div class="container"> <!-- Button trigger modal --> <center> <button type="button" style="padding:0px; margin-bottom:0px;line-height:0px;border:0px!important;background-color:transparent!important;" class="btn btn-primary video-btn" data-toggle="modal" data-src="https://www.youtube.com/embed/h7M7f-afhvY" data-target="#myModal"> <a class="play-btn" href="#"></a> </button></center> <!-- Modal --> <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div cla
CodePen
codepen.io โบ EdWise โบ pen โบ gOOvGgw
Modal Pop-up with YouTube iframe and jQuery
<main> <h1>Modal Pop-up</h1> <a href="#" class="watch-more">Click here</a> <!-- The Modal --> <div id="modal" class="modal"></div> <div class="video-popup"> <a class="close">×</a> <!-- Modal content --> <div class="video-wrapper"> <div class="video-container"> <iframe width="560" height="315" src="https://www.youtube.com/embed/sCL0SOsxiUc" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> </div> </div> </div> </main>
CodePen
codepen.io โบ luvuongle โบ pen โบ RyVEGG
Video Popup Modal
<div class="modal" id="modal"> <div class="close"><span class="close" id="close">×</span></div> <div class="modal-video-container" id="mdc"> <iframe class="video-popup" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen id="modal-video"></iframe> </div> </div> <div class="container"><a class="video-banner-link" href="https://www.youtube.com/embed/kY5G8s99Fl8?autoplay=1" data-vidup> <video class="video-banner" src="https://www.videvo.net/videvo_files/converted/2014_07/preview/Falls9.mov21113.webm" autoplay muted replay> </video></a> <a class="video-banner-link" href="https://www.youtube.com/embed/NY5S6-m97VM?autoplay=1" data-vidup> <video class="video-banner" src="https://www.videvo.net/videvo_files/converted/2012_08/preview/hd0026.mov99357.webm" autoplay replay> </video></a></div>
CodePen
codepen.io โบ shaileshp1089 โบ pen โบ vYLYZvo
Stop YouTube video on close of bootstrap 4 popup
<!-- Button trigger modal --> <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#VideoPop"> Launch demo modal </button> <!-- Modal --> <div class="modal fade VideoPopup" id="VideoPop" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true"> <div class="modal-dialog modal-dialog-centered modal-lg" role="document"> <div class="modal-content"> <div class="modal-body p-0"> <iframe width="100%" height="600" src="https://www.youtube.com/embed/X7R-q9rsrtU" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> </div> </div> </div> </div>
CodePen
codepen.io โบ colinrei โบ pen โบ JrrYam
VideoJS Youtube Player Popup Modal
<p> <a class="playvideo" href="#playvideo">Play Video</a> </p> <video id="vid1" class="video-js vjs-default-skin" controls width="640" height="264" data-setup='{"techOrder": ["youtube"], "sources": [{ "type": "video/youtube", "src": "https://www.youtube.com/watch?v=xjS6SftYQaQ"}] }' > </video> ... videojs.options.flash.swf = "video-js.swf"; $('document').ready(function(){ $('.open-popup-link').magnificPopup({ type:'inline', midClick: true }); $('.open-popup-link').on('click',function(){ videojs('vid1').play(); }); $('.playvideo').on('click', function(){ videojs('vid1').play(); }); })
Top answer 1 of 2
8
According to Ingus's solution you could overlay an div on your iframe like i did here:
$(document).ready(function() {
autoPlayYouTubeModal();
});
function autoPlayYouTubeModal() {
var trigger = $('.trigger');
trigger.click(function(e) {
e.preventDefault();
var theModal = $(this).data("target");
var videoSRC = $(this).attr("src");
var videoSRCauto = videoSRC + "?autoplay=1";
$(theModal + ' iframe').attr('src', videoSRCauto);
$(theModal).on('hidden.bs.modal', function(e) {
$(theModal + ' iframe').attr('src', '');
});
});
};
.holder {
width: 560;
height: 315px;
position: relative;
}
.frame {
width: 100%;
height: 100%;
}
.overlay {
position: absolute;
top: 0;
left: 0;
width: 560%;
height: 315px;
cursor: pointer;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<div class="holder">
<iframe width="560" height="315" src="https://www.youtube.com/embed/VF1Yz05iQM0" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
<div class="overlay trigger" src="https://www.youtube.com/embed/VF1Yz05iQM0" data-target="#videoModal" data-toggle="modal"></div>
</div>
<div class="modal fade" id="videoModal" tabindex="-1" role="dialog" aria-labelledby="videoModal" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<button type="button" class="close btn-round btn-primary" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<div class="embed-responsive embed-responsive-16by9">
<iframe class="embed-responsive-item" src="" allowfullscreen></iframe>
</div>
</div>
</div>
</div>
Working fiddle: https://jsfiddle.net/nqxeo695/
Notice: you should better use own images or screenshots of the videos instead of iframes, because each iframe will load the video instantly. The more videos you put on your site, the longer your site will need to load.
2 of 2
2
I am using the following example for bootstrap 3/4. it worked for me.
to show youtube thumnail of video
<img src="https://img.youtube.com/vi/<?= $row['videoID'] ?>/mqdefault.jpg" class="video-btn img-fluid cursor-pointer" data-toggle="modal" data-src="https://www.youtube.com/embed/<?= $row['videoID'] ?>" data-target="#myModal">
note that $row['videoID'] showing from my database
here is the modal that holds the video on iframe
<!-- Modal -->
<div class="modal videomodal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<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>
<!-- 16:9 aspect ratio -->
<div class="embed-responsive embed-responsive-16by9">
<iframe class="embed-responsive-item" src="" id="video" allowscriptaccess="always">></iframe>
</div>
and this simple script
<script type="text/javascript">
//for youtube video modal
$(document).ready(function() {
var $videoSrc;
$('.video-btn').click(function() {
$videoSrc = $(this).data( "src" );
});
console.log($videoSrc);
$('#myModal').on('shown.bs.modal', function (e) {
$("#video").attr('src',$videoSrc + "?rel=0&showinfo=0&modestbranding=1&autoplay=1" );
})
$('#myModal').on('hide.bs.modal', function (e) {
$("#video").attr('src',$videoSrc);
})
});
</script>
if you want to add some style. you can use this
.videomodal .modal-dialog {
max-width: 800px;
margin: 30px auto;
}
.videomodal .modal-body {
position:relative;
padding:0px;
}
.videomodal .close {
position:absolute;
right:-30px;
top:0;
z-index:999;
font-size:2rem;
font-weight: normal;
color:#fff;
opacity:1;
}
.cursor-pointer{
cursor: pointer;
}
CodePen
codepen.io โบ JacobLett โบ pen โบ ExmqNLb
Play YouTube or Vimeo Video in Modal - Bootstrap 5
<div class="container"> <h1>Play YouTube or Vimeo Videos in Bootstrap 5 Modal</h1> <!-- Button trigger modal --> <button type="button" class="btn btn-primary video-btn" data-bs-toggle="modal" data-src="https://www.youtube.com/embed/Jfrjeg26Cwk" data-bs-target="#myModal"> Play Video 1 - autoplay </button> <!-- Button trigger modal --> <button type="button" class="btn btn-primary video-btn" data-bs-toggle="modal" data-src="https://www.youtube.com/embed/IP7uGKgJL8U" data-bs-target="#myModal"> Play Video 2 </button> <!-- Button trigger modal --> <button type="button" class="btn btn-primary video-b
CodePen
codepen.io โบ xaixai โบ pen โบ LxKLeE
YouTube Video Popup
function videoPopup(objectName, videoUrl){ this.videoUrl= videoUrl; this.screenSize= $(window).width(); this.heightOfVideo= this.screenSize * .4; this.videoPop= '<div class="popUpWrapper">'+ '<div id="videoWrap"">'+ '<button type="button" class="videoClose" onclick="'+objectName+'.closeVideo()">X</button>'+ '<iframe width="100%" height="'+this.heightOfVideo+'" src="'+this.videoUrl+'" frameborder="0" allowfullscreen></iframe></div>'+ '</div>', this.closeVideo= function(){ $('.blackOut').fadeOut('slow'); $('.popupAlignCenter').html(""); }, this.launchPopUp= function(){ $(window).scroll(function(
CodePen
codepen.io โบ smallma009 โบ pen โบ JKEQEd
Youtube-Popup-Video
<a href="#" id="showPopup">Click</a> <div>Demo: Click to play Youtube</div> <div class="bg" style="display:none"></div> <div class="popup" style="display:none;height: 100%; width:100%;"> <iframe id="player" class="test3" src="//www.youtube.com/embed/Q_WHGV5bejk" frameborder="0" allowfullscreen></iframe> </div>