浏览器全屏切换
/**
* 全屏切换
* @returns
*/
const fullscreen = () => {
// 是否可以切换到全屏状态
let enabled = document.fullscreenEnabled || document.mozFullScreenEnabled || document.webkitFullscreenEnabled || document.msFullscreenEnabled;
if (!!enabled !== true) return ltNotify.danger("此终端不支持全屏");
// fullscreenElement属性返回正处于全屏状态的Element节点,如果当前没有节点处于全屏状态,则返回null。
let element = document.fullscreenElement || document.mozFullScreenElement || document.webkitFullscreenElement;
if (!!element) {
if (document.exitFullscreen) document.exitFullscreen();
else if (document.msExitFullscreen) document.msExitFullscreen();
else if (document.mozCancelFullScreen) document.mozCancelFullScreen();
else if (document.webkitExitFullscreen) document.webkitExitFullscreen();
else console.error("此终端不支持全屏");
} else {
element = document.documentElement;
if (element.requestFullscreen) element.requestFullscreen();
else if (element.mozRequestFullScreen) element.mozRequestFullScreen();
else if (element.msRequestFullscreen) element.msRequestFullscreen();
else if (element.webkitRequestFullscreen) element.webkitRequestFullScreen();
else console.error("此终端不支持全屏");
};
};
版权声明:
本站所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自
CaptainTwo!
喜欢就支持一下吧