目录

JavaScript Fullscreen API


全屏 API

Fullscreen API 具有处理全屏 HTML 元素的方法和属性。

示例

以全屏模式显示 <video> 元素:

/* Get the element you want to display in fullscreen */
var elem = document.getElementById("myvideo");

/* Execute the openFullscreen() function to open the video in fullscreen. Include prefixes for browsers that do not support the requestFullscreen property */
function openFullscreen() {
  if (elem.requestFullscreen) {
    elem.requestFullscreen();
  } else if (elem.webkitRequestFullscreen) { /* Safari */
    elem.webkitRequestFullscreen();
  } else if (elem.msRequestFullscreen) { /* IE11 */
    elem.msRequestFullscreen();
  }
}
亲自试一试 »

全屏属性和方法

Property/Method Description
exitFullscreen() Cancels the element in fullscreen mode
fullscreenElement Returns the element that is in full-screen mode,
fullscreenEnabled() Returns true if the document can be viewed in fullscreen mode
requestFullscreen() Opens an element in fullscreen mode