typescript設置全屏
阿新 • • 發佈:2018-12-21
defined 類型 let urn call javascrip lock script scree
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即可
typescript設置全屏