【发布时间】:2016-10-03 18:00:31
【问题描述】:
我正在尝试阻止模式中的视频在它们关闭时播放。问题是我的模态脚本将模态从其原始位置移动到关闭</body> 标记之前。因此,从技术上讲,在模态窗口上方停止视频脚本,在模态窗口关闭后视频永远不会停止播放。
这是我使用的模态脚本https://github.com/VodkaBears/Remodal
JQUERY 停止视频
var stopVideo = function ( element ) {
var video = element.querySelector( 'video' ); // script stops here with this error message: (index):684 Uncaught TypeError: Cannot read property 'querySelector' of null.
if ( video !== null ) {
video.stop();
}
};
$('.remodal-close').click(function(){
var id = this.id || this.getAttribute( 'data-remodal-id' );
var modal = document.querySelector( id );
//closePopup();
console.log("has video stopped? 1");
stopVideo( modal );
console.log("has video stopped? 2");
});
模态的HTML
<div class="remodal" data-remodal-id="modal" role="dialog" aria-labelledby="modal1Title" aria-describedby="modal1Desc">
<button data-remodal-action="close" class="remodal-close" aria-label="Close"></button>
<div class="video-container clearfix">
<div class="video clearfix">
<embed width="200" height="113" src="https://www.youtube.com/embed/xxxxxxxx?autoplay=1" frameborder="0" allowfullscreen>
</div>
</div>
</div>
【问题讨论】:
标签: jquery video jquery-selectors popup pause