I am looking to create a pop-up window containing a Vimeo video inside. I have a div on my webpage with an id of "showVideo". When this div is clicked, I want to display a pop-up (new div with the id of "opened-video"). The "opened-video" div contains an iframe with the Vimeo video embedded, like so:
<iframe id="video-iframe" src="https://player.vimeo.com/video/102895556?autoplay=1" width="500" height="281" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
The autoplay feature is enabled for this iframe using the ?autoplay=1 parameter in the source URL.
Here is my JavaScript code:
jQuery(document).ready(function(){
jQuery('#showVideo').click(function() {
jQuery('#opened-video').fadeIn().html('<iframe id="video-iframe" src="https://player.vimeo.com/video/102895556?autoplay=1" width="500" height="281" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe><img src="<?php echo get_template_directory_uri()?>/images/resp-menu-close.png" alt="Close video" onClick="closeDiv()" id="close-video" />');
});
});
This setup is currently functioning as intended.
You may notice an image tag within the html() function that serves the purpose of closing the "opened-video" section. This is achieved through a JavaScript function:
function closeDiv() {
document.getElementById('opened-video').style.display = "none";
}
While this method successfully hides the "opened-video" div, the Vimeo video continues playing in the background, emitting sound. How can I stop the video when clicking on the "close-video" image? Is there a way to remove the autoplay parameter (?autoplay=1) upon clicking the image? Any alternative suggestions are welcome.
Below is the HTML structure:
<img src="<?php echo get_template_directory_uri()?>/images/play-real.png" alt="Play real" id="showVideo" />
<div class="video-front" id="opened-video">
</div>