javascript - HTML - 退出全屏视频并暂停在 Google Chrome 上不起作用
问题描述
我有一个视频,全屏点击它运行良好,但是当我按下退出键或取消全屏时,视频仍在播放并且没有暂停音频。我在 Mozilla Firefox 中尝试了我的代码并且它可以工作,但是当我在 Google Chrome 上尝试它时它不工作。请帮助谢谢。
这是我的代码
// this should have worked...
const query = matchMedia('@media (device-width: 100vw) and (device-height: 100vh)');
query.onchange = e => {
if (query.matches) console.log('entered FS');
else console.log('exit FS');
}
//... but it doesn't
// so here is the hack...
let fs_elem = null;
myFSHack.addEventListener('transitionend', e => {
const prev = fs_elem;
fs_elem = document.querySelector(':fullscreen');
if (!fs_elem && prev === myvid) {
myvid.pause();
console.log('exit fullscreen')
}
});
#myFSHack {
max-height: 0;
transition: max-height .1s;
display: inline-block;
position: absolute;
z-index: -1;
pointer-events: none
}
@media (device-width: 100vw) and (device-height: 100vh) {
#myFSHack {/* trigger the transition */
max-height: 1px;
}
}
:root,body{margin:0;}
video {max-width: 100vw;}
<span id="myFSHack"></span><!-- This Line of Code this is the one which helps me to pause the full screen video when escaped or cancel -->
<h5>Click the View Full Screen</h5>
<video id="myvid" controls loop src="video/flashtrailer.mp4"></video>
解决方案
推荐阅读
- javascript - 返回方法而不返回任何值JavaScript?
- c++ - 使用 Google Mock 模拟非虚拟功能?
- java - 如何将正文检索为 JSON Play 框架 1.5
- javascript - document.cookie 不适用于 Firefox 中的 https://httpbin.org/cookies 站点
- html - 使用 ::after 添加中心输入字段和图标
- javascript - SAIKU UI 在视图之间共享全局变量
- sql - 无法获取记录 SQL
- django - 如何使用 djongo 连接器从 django 确保不会将空字段插入到 mongodb 集合中?
- c# - 尝试创建 V8ScriptEngine 实例失败并出现 IExpando 错误
- vba - 使用 VBA 查找、突出显示和列出在文档中找到的单词实例的计数