我試圖做一個嵌入式視頻播放,但是當我做他們都在同一時間播放。我花了兩天試圖解決這個問題,但無濟於事。 有人可以幫忙,我的編碼經驗有限。彈出模式jquery播放現有的嵌入式YouTube視頻時,試圖播放另一個
下面是代碼:
HTML:
<div class="play"><a data-popup-open="popup-1" href="#"></a></div>
<div class="popup" data-popup="popup-1">
<div class="popup-inner">
<iframe id="video" width="854" height="480" frameborder="0" allowfullscreen></iframe>
<a class="popup-close" data-popup-close="popup-1" href="#">x</a>
</div>
<div class="play"><a data-popup-open="popup-2" href="#"></a></div>
<div class="popup" data-popup="popup-2">
<div class="popup-inner">
<iframe id="video2" width="854" height="480" frameborder="0" allowfullscreen></iframe>
<a class="popup-close" data-popup-close="popup-2" href="#">x</a>
</div>
CSS:
.popup {
width: 100%;
height: 100%;
display: none;
position: fixed;
top: 0px;
left: 0px;
background: rgba(0,0,0,0.75);
z-index: 999;
}
.popup-inner {
max-width: 854px;
width: 90%;
padding: 0px;
position: fixed;
top: 53%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
height: auto;
min-width: 854px;
}
iframe {
border: 1px solid #151515);
border-radius: 7px !important;
z-index: 12;
}
.popup-close {
position: absolute;
width: 28px;
height: 28px;
padding-top: 4px;
padding-right: 2px;
padding-left: 2px;
display: inline-block;
position: absolute;
top: 0px;
right: -8px;
transition: ease 0.25s all;
-webkit-transform: translate(50%, -50%);
transform: translate(50%, -50%);
border-radius: 1000px;
background: rgba(0,0,0,0.8);
font-family: Arial, Sans-Serif;
font-size: 20px;
text-align: center;
line-height: 100%;
color: #fff;
z-index:13;
}
JAVASCRIPT
$(function() {
//----- OPEN
$('[data-popup-open]').on('click', function(e) {
var targeted_popup_class = jQuery(this).attr('data-popup-open');
$('[data-popup="' + targeted_popup_class + '"]').fadeIn(350);
$("#video").attr('src','https://www.youtube.com/embed/mz8qGSaPvI8');
$("#video")[0].src += "?autoplay=1&modestbranding=1";
$("#video2").attr('src','https://www.youtube.com/embed/mz8qGSaPvI8');
$("#video2")[0].src += "?autoplay=1&modestbranding=1";
e.preventDefault();
});
//----- CLOSE
$('[data-popup-close]').on('click', function(e) {
var targeted_popup_class = jQuery(this).attr('data-popup-close');
$('[data-popup="' + targeted_popup_class + '"]').fadeOut(350);
$("#video, #video2").attr('src','');
e.preventDefault();
});
});