HTML5没有提供制作视频全屏的方法,而是提供了并行的Fullscreen APIdefines an API for elements to display themselves fullscreen.
这可以应用于任何元素,包括视频.
Browser support已经不错了,但是Internet Explorer和Safari需要前缀版本.
当堆栈片段Sandbox 规则打破它时,会提供一个external demo.
<div id="one">
One
</div>
<div id="two">
Two
</div>
<button>one</button>
<button>two</button>
div {
width: 200px;
height: 200px;
}
#one { background: yellow; }
#two { background: pink; }
addEventListener("click", event => {
const btn = event.target;
if (btn.tagName.toLowerCase() !== "button") return;
const id = btn.textContent;
const div = document.getElementById(id);
if (div.requestFullscreen)
div.requestFullscreen();
else if (div.webkitRequestFullscreen)
div.webkitRequestFullscreen();
else if (div.msRequestFullScreen)
div.msRequestFullScreen();
});
HTML5没有提供使视频全屏显示的方法,但parallel Fullscreen specification提供了requestFullScreen
方法,该方法允许使任意元素(包括<video>
个元素)全屏显示.
它有experimental support in a number of browsers个.
Note: this has since been removed from the specification.
从HTML5 spec( compose 本文时:09年6月):
用户代理不应提供 播放视频的公共接口 全屏显示.脚本,与 精心制作的视频文件,可以 欺骗用户,使其认为 显示了系统模式对话框, 并提示用户输入密码. 还有"仅仅"的危险. 烦人,页面启动 当链接被 已单击或已导航页面.相反, 特定于用户代理的界面功能 可以被提供来容易地允许 用户可获得全屏播放 模式.
浏览器可以提供用户界面,但不应该提供可编程的界面.