I have a bootstrap modal on a shopify page with a vimeo video embedded, I was initially having an issue where I closed the modal but could still hear the video playing. I was finally able to stop that with the code below.
But now when I reopen the modal for a 2nd time it is empty. Any suggestions?
<script>
( function($) {
function iframeModalOpen(){
$('.modalButton').on('click', function(e) {
var src = $(this).attr('data-src');
var width = $(this).attr('data-width') || 640;
var height = $(this).attr('data-height') || 360;
var allowfullscreen = $(this).attr('data-video-fullscreen');
$("#modalYT iframe").attr({
'src': src,
'height': height,
'width': width,
'allowfullscreen':''
});
});
$('#modalYT').on('hidden.bs.modal', function(){
$(this).find('iframe').html("");
$(this).find('iframe').attr("src", "");
});
}
$(document).ready(function(){
iframeModalOpen();
});
} ) ( jQuery );
</script>