合规国际互联网加速 OSASE为企业客户提供高速稳定SD-WAN国际加速解决方案。 广告
>[info] 全屏切换 ~~~ /** * 让浏览器全屏切换 * @param el dom * @param fullscreen 是否全屏 * @returns {boolean} 全屏状态 */ export function toggleFullscreen(el, fullscreen) { if (!el) { el = document.documentElement; } if (typeof fullscreen === 'undefined' || fullscreen === null) { fullscreen = !isFullscreen(); } if (fullscreen) { const rfs = ( el.requestFullScreen || el.webkitRequestFullScreen || el.mozRequestFullScreen || el.msRequestFullScreen ); if (rfs) { rfs.call(el); } else { throw new Error('您的浏览器不支持全屏模式'); } } else { const cfs = ( document.exitFullScreen || document.webkitCancelFullScreen || document.mozCancelFullScreen || document.msExitFullscreen ); if (cfs) { cfs.call(document); } } return fullscreen; } ~~~ * **使用:** ~~~ /* 全屏切换 */ changeFullscreen() { try { this.fullscreen = toggleFullscreen(); } catch (e) { this.$message.error("您的浏览器不支持全屏模式"); } }, ~~~ ~~~ data() { return { // 是否全屏状态 fullscreen: false }; }, ~~~ >[info] 检查全屏状态 ~~~ /** * 获取当前是否是全屏状态 * @returns {boolean} */ export function isFullscreen() { return !!( document.fullscreenElement || document.webkitFullscreenElement || document.mozFullScreenElement || document.msFullscreenElement ); } ~~~ * **使用:** ~~~ /* 检查全屏状态 */ checkFullscreen() { this.fullscreen = isFullscreen(); }, ~~~