Skip to content

Instantly share code, notes, and snippets.

@Nikschavan Nikschavan/modal.js
Last active Sep 25, 2018

Embed
What would you like to do?
Modal Element - Ultimate Addon's For Visual composer: Play YouTube video automatically when modal is opened.
<script>
$ModalvideoID = 'mV7KeHRu6os';
$width = '450';
$height = '283';
function modalAutoPlayVideo(vcode, width, height){
"use strict";
jQuery(".ult_modal-body.ult-youtube").html('<iframe width="'+width+'" height="'+height+'" src="https://www.youtube.com/embed/'+vcode+'?autoplay=1&loop=1&rel=0&wmode=transparent" frameborder="0" allowfullscreen wmode="Opaque"></iframe>');
}
function modalStopVideo(vcode, width, height){
"use strict";
jQuery(".ult_modal-body.ult-youtube").html('<iframe width="'+width+'" height="'+height+'" src="https://www.youtube.com/embed/'+vcode+'" frameborder="0" allowfullscreen wmode="Opaque"></iframe>');
}
jQuery(document).on('onUVCModalPopupOpen', function(event) {
event.preventDefault();
modalAutoPlayVideo($ModalvideoID,$width,$height);
});
jQuery(document).on('onUVCModalPopUpClosed', function(event) {
event.preventDefault();
modalStopVideo($ModalvideoID,$width,$height);
});
</script>
@EvokeDesigns

This comment has been minimized.

Copy link

commented Sep 25, 2018

This worked so well! It is the only code i have found that will autoplay and stop when modal box is closed. But now all the modal boxes i have play the video/sound in the background even though they are just for text. How do i use this code to only be for one modal box?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.