Last active
September 25, 2018 22:37
-
-
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.
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
<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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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?