Created
July 10, 2014 19:21
-
-
Save Reyjay/acb4734296b40dcad9ec to your computer and use it in GitHub Desktop.
Open a youtube video in a modal and stop it when the modal is closed
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
<!--- This is the video link ---> | |
<a href="##"><img src="#videoItem.getImageUrl()#" data-link="#videoItem.getVideoLink()#" alt="#videoItem.getTitle()#"></a> | |
<!-- Video modal --> | |
<div class="modal videoModal" id="videoModal"> | |
<div class="modal-dialog"> | |
<div class="modal-content"> | |
<div class="modal-header"> | |
<button type="button" class="close" data-dismiss="modal" aria-hidden="true"><span class="glyphicon glyphicon-remove-sign"></span></button> | |
</div> | |
<div class="modal-body"> | |
<div class="embed-container"><iframe class="videoElement" src="" frameborder="0" allowfullscreen></iframe></div> | |
</div> | |
</div> | |
</div> | |
</div> | |
<script> | |
//Change video modal when click on image | |
$('.videoResource ul li img').click(function(){ | |
var videoLink = $(this).attr('data-link'); | |
$('.videoElement').attr('src',videoLink); | |
$('##videoModal').modal({show:true}); | |
}); | |
//Stop video when modal closes | |
$('.videoModal').each(function(){ | |
$(this).on('hidden.bs.modal', function (e) { | |
var videoObj = $(this).find('iframe'); | |
var videoSrc = $(this).find('iframe').attr('src'); | |
$(videoObj).attr('src',''); | |
$(videoObj).attr("src", videoSrc); | |
}); | |
}); | |
</script |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment