typescript设置全屏
fullScreen() { document.getElementById("fullScreen").style.display = "none"; document.getElementById("exitScreen").style.display = "block"; let el = document.documentElement as any; let rfs = el.requestFullScreen || el.webkitRequestFullScreen || el.mozRequestFullScreen || el.msRequestFullscreen; if (typeof rfs != "undefined" && rfs) { rfs.call(el); }; return; } //退出全屏 exitScreen() { document.getElementById("fullScreen").style.display = "block"; document.getElementById("exitScreen").style.display = "none"; let cfs = document as any; if (cfs.exitFullscreen) { cfs.exitFullscreen(); } else if (cfs.webkitCancelFullScreen) { cfs.webkitCancelFullScreen(); } else { cfs.msExitFullscreen(); } }
特别注意:typescript的类型检查时,document内会报msRequestFullscreen不是documentElement的属性。解决方法:重新赋值document as any即可