使用 YouTube iframe 嵌入播放器,有没有办法以编程方式触发全屏?我想删除默认控件(使用controls=0),但随后能够自行创建自定义全屏按钮。
使 iframe 不是全屏而是全页:
function fullscreen() {
var vid = document.getElementById("vid");
vid.style.position = "absolute";
vid.style.width = "100vw";
vid.style.height = "100vh";
vid.style.top = "0px";
vid.style.left = "0px";
document.getElementById("exit").style.display = "inline";
}
function exitfullscreen() {
var vid = document.getElementById("vid");
vid.style.position = "";
vid.style.width = "";
vid.style.height = "";
vid.style.top = "";
vid.style.left = "";
document.getElementById("exit").style.display = "none";
}
<iframe width="560" height="315" src="https://www.youtube.com/embed/fq6qcvfZldE?rel=0&controls=0&showinfo=0" frameborder="0" id="vid" allowfullscreen></iframe>
<button onClick="fullscreen()">Fullscreen</button>
<button style="position: fixed;
bottom: 5px;
right: 5px;
display: none;
z-index: 2000;" id="exit" onClick="exitfullscreen()">Exit Fullscreen</button>
The full page button in the right upper corner of the code snippet also works this way. If you want to make the browser full screen you could try document.requestFullscreen();
, but this is still experimental and works on very few browsers. Take a look at the MDN https://developer.mozilla.org/en-US/docs/Web/API/Fullscreen_API topic of this function.
编辑:刚刚发现这个:https://developers.google.com/youtube/?csw=1#player_apis https://developers.google.com/youtube/?csw=1#player_apis,官方 YouTube 播放器 API。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)