Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Nikschavan
Last active September 25, 2018 22:37
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nikschavan/cf325e0b627c87cf86e566f355f7faca to your computer and use it in GitHub Desktop.
Save Nikschavan/cf325e0b627c87cf86e566f355f7faca to your computer and use it in GitHub Desktop.
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
Copy link

EvokeDesigns 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