API toàn màn hình JavaScript
API toàn màn hình
API toàn màn hình có các phương thức và thuộc tính để xử lý các phần tử HTML ở chế độ toàn màn hình.
Ví dụ
Hiển thị phần tử <video> ở chế độ toàn màn hình:
/* 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();
}
}
Hãy tự mình thử »Thuộc tính và phương thức toàn màn hình
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 |