下面是单击按钮时视频打开然后关闭后,如果我们重新尝试打开视频的代码。仅打开弹出窗口,但视频将不可见。
请帮忙
jQuery的:
$("[data-media]").on("click", function(e) {
e.preventDefault();
var $this = $(this);
var videoUrl = $this.attr("data-media");
var popup = $this.attr("href");
var $popupIframe = $(popup).find("iframe");
$popupIframe.attr("src", videoUrl);
var left = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
var left = left/2 - 340;
var top = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
var top = top/2 - 180
document.getElementById("vid").style.top = top + "px";
document.getElementById("vid").style.left = left + "px";
$this.closest(".page").addClass("show-popup");
$('.page iframe').attr("src", '');
});
$(".popup").on("click", function(e) {
e.preventDefault();
e.stopPropagation();
$(".page").removeClass("show-popup");
});
$(".popup > iframe").on("click", function(e) {
e.stopPropagation();
});
HTML:
<div class="page"> <!-- class "page" is required for video to work-->
<div class="popup" id="media-popup"> <!-- video embedded -->
<iframe id="vid" src="http://testvideo.com" width="640" height="360" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
</div><!-- popup -->
</div>