rt-sim-training-client/src/utils/screen.js

52 lines
1.4 KiB
JavaScript
Raw Normal View History

2019-08-02 10:36:17 +08:00
// 判断全屏模式是否是可用
2019-07-26 13:32:43 +08:00
export function isFullscreenEnabled() {
2019-08-02 10:36:17 +08:00
return document.fullscreenEnabled ||
2019-07-26 13:32:43 +08:00
document.mozFullScreenEnabled ||
document.webkitFullscreenEnabled ||
document.msFullscreenEnabled || false;
}
2019-08-02 10:36:17 +08:00
// 判断浏览器是否全屏
2019-07-26 13:32:43 +08:00
export function isFullscreen() {
2019-08-02 10:36:17 +08:00
return document.fullscreenElement ||
2019-07-26 13:32:43 +08:00
document.msFullscreenElement ||
document.mozFullScreenElement ||
document.webkitFullscreenElement || false;
}
2019-08-02 10:36:17 +08:00
// 启动全屏
2019-07-26 13:32:43 +08:00
export function launchFullscreen() {
2019-08-02 10:36:17 +08:00
if (isFullscreenEnabled()) {
const 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();
}
}
2019-07-26 13:32:43 +08:00
}
2019-08-02 10:36:17 +08:00
// 退出全屏
2019-07-26 13:32:43 +08:00
export function exitFullscreen() {
2019-08-02 10:36:17 +08:00
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();
}
}
2019-07-26 13:32:43 +08:00
}