一、实现页面全屏
1 function doFullscreen (el) { 2 if (el == null) { 3 el = document.documentElement 4 } 5 const func = el.requestFullscreen || el.requestFullScreen || el.webkitRequestFullScreen || el.mozRequestFullScreen || el.msRequestFullScreen 6 if (!func) { 7 throw new Error("您的浏览器不支持全屏模式"); 8 } 9 func.call(el) 10 }
二、退出全屏
1 function doExitFullscreen () { 2 const func = document.exitFullscreen || document.exitFullScreen || document.webkitCancelFullScreen || document.mozCancelFullScreen || document.msExitFullscreen 3 func && func.call(document); 4 }
三、检测是否为全屏
1 function doCheckFullscreen () { 2 return !!(document.fullscreenElement || document.webkitFullscreenElement || document.mozFullScreenElement || document.msFullscreenElement) 3 }