javascript - 模态关闭时视频不停止
问题描述
在下一页https://yourhippo.com/course-search/我试图让视频在模式关闭时停止我不确定关闭视频的最佳选择是什么我尝试了以下但它似乎不起作用
'''( function( w, d ) {
'use strict';
// Get the modal
var el = d.getElementsByClassName( 'container' )[0];
var modal = d.getElementById( 'id01' );
// When the user clicks anywhere outside of the modal, close it
w.onclick = function ( event ) {
if ( event.target == modal ) {
modal.style.display = 'none';
}
};
d.getElementsByClassName( 'close' )[0].addEventListener( 'click',
function() {
d.getElementById( 'id01' ).style.display = 'none';
while ( el.firstChild ) {
el.removeChild( el.firstChild );
}
}, false );
}( window, document ));'''
解决方案
您可以使用 .pause() 方法。
<!-- Add the vimeo api. -->
<script src="https://player.vimeo.com/api/player.js"></script>
var iframe = document.querySelector('iframe'); // the iframe that is already in your HTML
var player = new Vimeo.Player(iframe); // init the vimeo video player
player.pause() // pauses the video
( function( w, d ) {
'use strict';
// Get the modal
var el = d.getElementsByClassName( 'container' )[0];
var modal = d.getElementById( 'id01' );
// When the user clicks anywhere outside of the modal, close it
w.onclick = function ( event ) {
if ( event.target == modal ) {
modal.style.display = 'none';
var iframe = document.querySelector('iframe'); // the iframe that is already in your HTML
var player = new Vimeo.Player(iframe); // init the vimeo video player
player.pause() // pauses the video
}
};
d.getElementsByClassName( 'close' )[0].addEventListener( 'click',
function() {
d.getElementById( 'id01' ).style.display = 'none';
while ( el.firstChild ) {
el.removeChild( el.firstChild );
}
}, false );
}( window, document ));
推荐阅读
- java - Jaeger 跟踪配置端点
- java - IntelliJ 仅打印所需输出的一部分(Java)
- salesforce - 闪电:输入日期字段验证
- html - html预加载和预取有什么区别?
- maven - 在 Jenkins 上使用 maven-release-plugin 发布时出错
- python - Selenium 找不到元素,即使它们存在
- excel - 如何将excel文件转换为CSV并批量跳过一些行?
- python - Appveyor:如何在 Windows 映像上运行 2 个作业,而在 Linux 映像上只运行一个?
- python - 默认情况下,conda 命令在 conda 环境中不可用
- python - 在 Python 3 上使用 WHILE 测试十进制输入无法使其工作