我使用以下代码以模态显示嵌入的视频,但是当我单击关闭按钮时,背景中的音频不会停止。对 Stack Overflow 上提供的解决方案进行了很多尝试,但没有任何帮助。
HTML 代码:
<div class="container" id="photocontainer">
<div class="row pt-5 ">
<div class="col-sm-3" id="photocol">
<img src="img/Cinematography/1Jacinta-Tyler.jpg" style="width:100%" onclick="openModal();currentSlide(1)" class="hover-shadow cursor">
</div>
<div class="col-sm-3" id="photocol">
<img src="img/Cinematography/2Amanda-Mark.jpg" style="width:100%" onclick="openModal();currentSlide(2)" class="hover-shadow cursor">
</div>
<div id="myModal" class="modal">
<span class="close cursor" onclick="closeModal();">×</span>
<div class="modal-content">
<div class="mySlides" >
<iframe src="player.vimeo.com/video/…; class="mt-5" width="740" height="316" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
<p>
<a href="vimeo.com/255103005"; id="clr">
<b>Jacinta & Tyler</b>
</a>
By <a href="vimeo.com/beautifullifestudios"; id="clr">Beautiful Life Studios</a>
.</p>
</div>
脚本:
<script>
function openModal() {
document.getElementById('myModal').style.display = "block";
}
function closeModal() {
document.getElementById('myModal').style.display = "none";
}
var slideIndex = 1;
showSlides(slideIndex);
function plusSlides(n) {
showSlides(slideIndex += n);
}
function currentSlide(n) {
showSlides(slideIndex = n);
}
function showSlides(n) {
var i;
var slides = document.getElementsByClassName("mySlides");
var dots = document.getElementsByClassName("demo");
var captionText = document.getElementById("caption");
if (n > slides.length) {slideIndex = 1}
if (n < 1) {slideIndex = slides.length}
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
for (i = 0; i < dots.length; i++) {
dots[i].className = dots[i].className.replace(" active", "");
}
slides[slideIndex-1].style.display = "block";
dots[slideIndex-1].className += " active";
captionText.innerHTML = dots[slideIndex-1].alt;
}
</script>