angular 项目中全屏 退出全屏 方法

function isFull() {

/*判断是否全屏*/

var isFullscreen = document.fullScreenElement //W3C

||

document.msFullscreenElement //IE

||

document.mozFullScreenElement //火狐

||

document.webkitFullscreenElement //谷歌

||

false;

if (!isFullscreen) {

var el = document.querySelector('.window');

if (el.requestFullscreen) {

el.requestFullscreen();

} else if (el.mozRequestFullScreen) {

el.mozRequestFullScreen();

} else if (el.webkitRequestFullscreen) {

el.webkitRequestFullscreen();

} else if (el.msRequestFullscreen) {

el.msRequestFullscreen();

}

} else {

if (document.exitFullscreen) {

document.exitFullscreen();

} else if (document.msExitFullscreen) {

document.msExitFullscreen();

} else if (document.mozCancelFullScreen) {

document.mozCancelFullScreen();

} else if (document.webkitCancelFullScreen) {

document.webkitCancelFullScreen();

}

}

}

 

如报错  // 

 error TS2551: Property 'msExitFullscreen' does not exist on type 'Document'. Did you mean 'exitFullscreen'?
 error TS2339: Property 'mozCancelFullScreen' does not exist on type 'Document'.
 error TS2339: Property 'mozCancelFullScreen' does not exist on type 'Document'.
则改写为以下形式

 

fullScreen() {

/*判断是否全屏*/

var ell = document.getElementById('dashboard');

const el = ell as HTMLElement & {

mozRequestFullScreen(): Promise;

webkitRequestFullscreen(): Promise;

msRequestFullscreen(): Promise;

};

console.log(document);

let isFullscreen =

document['fullscreenElement'] || //W3C

document['msFullscreenElement'] || //IE

document['mozFullScreenElement'] || //火狐

document['webkitFullscreenElement'] || //谷歌

false;

if (!isFullscreen) {

if (el.requestFullscreen) {

el.requestFullscreen();

} else if (el.mozRequestFullScreen) {

el.mozRequestFullScreen();

} else if (el.webkitRequestFullscreen) {

el.webkitRequestFullscreen();

} else if (el.msRequestFullscreen) {

el.msRequestFullscreen();

}

} else {

if (document.exitFullscreen) {

document.exitFullscreen();

} else if (document['msExitFullscreen']) {

document['msExitFullscreen']();

} else if (document['mozCancelFullScreen']) {

document['mozCancelFullScreen']();

} else if (document['webkitCancelFullScreen']) {

document['webkitCancelFullScreen']();

}

}

}

错误解除

你可能感兴趣的:(angular 项目中全屏 退出全屏 方法)