53 lines
1.6 KiB
JavaScript
53 lines
1.6 KiB
JavaScript
|
//判断全屏模式是否是可用
|
||
|
export function isFullscreenEnabled() {
|
||
|
return document.fullscreenEnabled ||
|
||
|
document.mozFullScreenEnabled ||
|
||
|
document.webkitFullscreenEnabled ||
|
||
|
document.msFullscreenEnabled || false;
|
||
|
}
|
||
|
|
||
|
//判断浏览器是否全屏
|
||
|
export function isFullscreen() {
|
||
|
return document.fullscreenElement ||
|
||
|
document.msFullscreenElement ||
|
||
|
document.mozFullScreenElement ||
|
||
|
document.webkitFullscreenElement || false;
|
||
|
}
|
||
|
|
||
|
//启动全屏
|
||
|
export function launchFullscreen() {
|
||
|
if (isFullscreenEnabled()) {
|
||
|
let element = document.documentElement;
|
||
|
if (element.requestFullScreen) {
|
||
|
element.requestFullScreen();
|
||
|
} else if (element.mozRequestFullScreen) {
|
||
|
element.mozRequestFullScreen();
|
||
|
} else if (element.msRequestFullscreen) {
|
||
|
element.msRequestFullscreen();
|
||
|
} else if (element.oRequestFullscreen) {
|
||
|
element.oRequestFullscreen();
|
||
|
} else if (element.webkitRequestFullScreen) {
|
||
|
element.webkitRequestFullScreen();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
//退出全屏
|
||
|
export function exitFullscreen() {
|
||
|
if (isFullscreen()) {
|
||
|
if (document.exitFullscreen) {
|
||
|
document.exitFullscreen();
|
||
|
} else if (document.msExitFullscreen) {
|
||
|
document.msExitFullscreen();
|
||
|
} else if (document.mozCancelFullScreen) {
|
||
|
document.mozCancelFullScreen();
|
||
|
} else if (document.mozExitFullScreen) {
|
||
|
document.mozExitFullScreen();
|
||
|
} else if (document.webkitExitFullscreen) {
|
||
|
document.webkitExitFullscreen();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|