How to pause a video/audio when modal windows is closed
- Example of how to pause a video or audio contained in a bootstrap-modal to prevent further hearing when the modal window is closed.
// Close Bootstrap Modal.
$('.close, .save, .cancel').on('click', function(e){
e.preventDefault();
var $this = $(this);
// get identifier modal window.
var modal = $this.data('custom');
$('#'+modal).modal('hide');
// check tag html5 for video and audio.
if (($('#id-'+modal).prop("tagName") == 'AUDIO')
|| ($('#id-'+modal).prop("tagName") == 'VIDEO')) {
if (!$('#el-'+modal).get(0).paused) {
$('#el-'+modal)[0].pause();
}
}
});
Written by Carlos Escobedo
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Jquery
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#