gpt4 book ai didi

css - 单击弹出窗口时如何暂停视频

转载 作者:行者123 更新时间:2023-11-28 15:12:14 30 4
gpt4 key购买 nike

我对编程世界还很陌生,我正在开发一个网站,该网站将有一个按钮可以播放 YouTube 上的视频。我在网上找到了如何创建弹出窗口,但是一旦我点击退出视频,它仍然会播放视频并且您可以听到它在后台播放。

我尝试了不同的方法,但仍然无法弄清楚我的代码有什么问题。这是我的代码:

.lightbox {
display: none;
position: fixed;
z-index: 999;
width: 100%;
height: 100%;
text-align: center;
top: 0;
left: 0;
background: rgba(0,0,0,0.8);
}
.lightbox:target {
outline: none;
display: block;
}


#videoModal {
border-radius: 0;
width: 870px;
margin:auto;}
#videoModal .modal-header {
background: #000;
border: 0;
color: #fff;
position: relative;
height:35px;
margin-bottom: 5px; }
#videoModal .modal-header h3 {
font-size: 18px;
line-height: 22px;
font-family:Arial, Helvetica, sans-serif;
padding:5px;}
#videoModal .modal-body {
height: 489px;
padding: 0;
max-height: none;
overflow: hidden; }
#videoModal .modal-footer:empty {
display: none !important; }
#videoModal .close {
background: none;
color: #fff;
font-size: 24px;
margin: 0;
opacity: 1;
position: absolute;
right: 0;
text-shadow: none;
top: 0;
width: 38px;
border-width: 0px !important;}
<a class="vid_link" data-fancybox-type="iframe" href="#img1"><img src="http://www.bbk.ac.uk/lib/images/general/PLAY.jpg" style="width:100%;height:auto;"></a> 


<!-- lightbox container hidden with CSS -->
<a href="#_" class="lightbox" id="img1">
<div id="videoModal" class="modal hide fade in" tabindex="-1" role="dialog" aria-labelledby="videoModalLabel" aria-hidden="false" style="display: block;">
<div class="modal-header">
<button type="button" class="close full-height" data-dismiss="modal" aria-hidden="true">X</button>
<h3>Mumford and Sons: Broad-Shouldered Beasts</h3>
</div>
<div class="modal-body"><iframe width="870px" height="489px" src="https://www.youtube.com/embed/84V4AQIZMUg?rel=0&autoplay=1" frameborder="0" allowfullscreen=""></iframe></div>
<div class="modal-footer"></div>
</div></a>

最佳答案

希望您能接受 JQuery。您可以在下面添加 JS 代码。确保从您的视频 iFrame 中删除 src,因为它将在文档准备就绪时以编程方式设置。给播放按钮分配一个id;我假设 id 是 playBtn。由于页面在刷新时跟踪最近的播放/暂停状态,如果按钮处于播放模式,我们只需要在加载时设置 src。单击播放按钮后,我们只会在空白和您的视频链接之间切换 src。答案中有一个更新的片段,但我知道由于 YouTube API,它在 Stackoverflow 中不起作用。因此,我给出了这个简短的描述,让您知道我做了什么。

$(document).ready(function(){
var isVisible = $('#img1:visible').length;
var src = 'https://www.youtube.com/embed/84V4AQIZMUg?rel=0&autoplay=1';

if(isVisible){
$('iframe').attr('src', src);
}


$('#playBtn, #img1').click(function(){
$('iframe').attr('src', $('iframe').attr('src')? "": src);
});

});

$(document).ready(function(){
var isVisible = $('#img1:visible').length;
var src = 'https://www.youtube.com/embed/84V4AQIZMUg?rel=0&autoplay=1';

if(isVisible){
$('iframe').attr('src', src);
}


$('#playBtn, #img1').click(function(){
$('iframe').attr('src', $('iframe').attr('src')? "": src);
});

});
.lightbox {
display: none;
position: fixed;
z-index: 999;
width: 100%;
height: 100%;
text-align: center;
top: 0;
left: 0;
background: rgba(0,0,0,0.8);
}
.lightbox:target {
outline: none;
display: block;
}


#videoModal {
border-radius: 0;
width: 870px;
margin:auto;}
#videoModal .modal-header {
background: #000;
border: 0;
color: #fff;
position: relative;
height:35px;
margin-bottom: 5px; }
#videoModal .modal-header h3 {
font-size: 18px;
line-height: 22px;
font-family:Arial, Helvetica, sans-serif;
padding:5px;}
#videoModal .modal-body {
height: 489px;
padding: 0;
max-height: none;
overflow: hidden; }
#videoModal .modal-footer:empty {
display: none !important; }
#videoModal .close {
background: none;
color: #fff;
font-size: 24px;
margin: 0;
opacity: 1;
position: absolute;
right: 0;
text-shadow: none;
top: 0;
width: 38px;
border-width: 0px !important;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a class="vid_link" data-fancybox-type="iframe" href="#img1"><img src="http://www.bbk.ac.uk/lib/images/general/PLAY.jpg" style="width:100%;height:auto;"></a>


<!-- lightbox container hidden with CSS -->
<a href="#_" class="lightbox" id="img1">
<div id="videoModal" class="modal hide fade in" tabindex="-1" role="dialog" aria-labelledby="videoModalLabel" aria-hidden="false" style="display: block;">
<div class="modal-header">
<button type="button" class="close full-height" data-dismiss="modal" aria-hidden="true">X</button>
<h3>Mumford and Sons: Broad-Shouldered Beasts</h3>
</div>
<div class="modal-body"><iframe width="870px" height="489px" frameborder="0" allowfullscreen=""></iframe></div>
<div class="modal-footer"></div>
</div></a>

关于css - 单击弹出窗口时如何暂停视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48095016/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com