A Pen by Adam Prakash Lewis on CodePen.
Created
January 30, 2019 15:14
-
-
Save tauraamui/f1f1a66bcdb09762696922a47cad5dc0 to your computer and use it in GitHub Desktop.
iFrame inside Bootstrap 3 modal
This file contains 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
<html lang="it_IT"> | |
<head> | |
<meta charset="utf-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<title></title> | |
<meta name="description" content=""> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
</head> | |
<body> | |
<div class="container"> | |
<div class="row"> | |
<div class="col-xs-12"> | |
<div class="page"> | |
<button type="button" class="bmd-modalButton" data-toggle="modal" data-bmdSrc="https://player.vimeo.com/video/18539129" data-bmdWidth="500" data-bmdHeight="281" data-target="#myModal">Vimeo</button> | |
<button type="button" class="bmd-modalButton" data-toggle="modal" data-bmdSrc="https://www.youtube.com/embed/cMNPPgB0_mU" data-bmdWidth="640" data-bmdHeight="480" data-target="#myModal" data-bmdVideoFullscreen="true">Youtube</button> | |
<button type="button" class="bmd-modalButton" data-toggle="modal" data-bmdSrc="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d91737.51273778046!2d12.566428499999994!3d44.06689465000003!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x132cc3a48fa6592b%3A0xc1f284db17f1449d!2sRimini+RN!5e0!3m2!1sit!2sit!4v1427492339750" data-bmdWidth="600" data-bmdHeight="450" data-target="#myModal">Google maps</button> | |
</div> | |
</div> | |
</div> | |
</div> | |
<footer> | |
<div class="modal fade" id="myModal"> | |
<div class="modal-dialog"> | |
<div class="modal-content bmd-modalContent"> | |
<div class="modal-body"> | |
<div class="close-button"> | |
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> | |
</div> | |
<div class="embed-responsive embed-responsive-16by9"> | |
<iframe class="embed-responsive-item" frameborder="0"></iframe> | |
</div> | |
</div> | |
</div><!-- /.modal-content --> | |
</div><!-- /.modal-dialog --> | |
</div><!-- /.modal --> | |
</footer> | |
<a href="https://github.com/filippo-quacquarelli/bmd-iframe" target="_blank" class="github-corner" aria-label="View source on Github"> | |
<svg width="80" height="80" viewBox="0 0 250 250" style="fill:#151513; color:#fff; z-index:99; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg> | |
</a> | |
<style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style> | |
</body> | |
</html> |
This file contains 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($) { | |
$.fn.bmdIframe = function( options ) { | |
var self = this; | |
var settings = $.extend({ | |
classBtn: '.bmd-modalButton', | |
defaultW: 640, | |
defaultH: 360 | |
}, options ); | |
$(settings.classBtn).on('click', function(e) { | |
var allowFullscreen = $(this).attr('data-bmdVideoFullscreen') || false; | |
var dataVideo = { | |
'src': $(this).attr('data-bmdSrc'), | |
'height': $(this).attr('data-bmdHeight') || settings.defaultH, | |
'width': $(this).attr('data-bmdWidth') || settings.defaultW | |
}; | |
if ( allowFullscreen ) dataVideo.allowfullscreen = ""; | |
// stampiamo i nostri dati nell'iframe | |
$(self).find("iframe").attr(dataVideo); | |
}); | |
// se si chiude la modale resettiamo i dati dell'iframe per impedire ad un video di continuare a riprodursi anche quando la modale è chiusa | |
this.on('hidden.bs.modal', function(){ | |
$(this).find('iframe').html("").attr("src", ""); | |
}); | |
return this; | |
}; | |
})(jQuery); | |
jQuery(document).ready(function(){ | |
jQuery("#myModal").bmdIframe(); | |
}); |
This file contains 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
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> | |
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script> |
This file contains 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
.page { | |
padding: 15px 0 0; | |
} | |
.bmd-modalButton { | |
display: block; | |
margin: 15px auto; | |
padding: 5px 15px; | |
} | |
.close-button { | |
overflow: hidden; | |
} | |
.bmd-modalContent { | |
box-shadow: none; | |
background-color: transparent; | |
border: 0; | |
} | |
.bmd-modalContent .close { | |
font-size: 30px; | |
line-height: 30px; | |
padding: 7px 4px 7px 13px; | |
text-shadow: none; | |
opacity: .7; | |
color:#fff; | |
} | |
.bmd-modalContent .close span { | |
display: block; | |
} | |
.bmd-modalContent .close:hover, | |
.bmd-modalContent .close:focus { | |
opacity: 1; | |
outline: none; | |
} | |
.bmd-modalContent iframe { | |
display: block; | |
margin: 0 auto; | |
} |
This file contains 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
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment