让页面全屏

IE8不支持,内核为trident的IE是支持的 W3C全部支持,但是前缀名不一样;

全屏方法为:

function fullScreen(ele) {
if (ele.requestFullscreen) {
ele.requestFullscreen();
} else if (ele.msRequestFullscreen) {
ele.msRequestFullscreen();
} else if (ele.mozRequestFullScreen) {
ele.mozRequestFullScreen();
} else if (ele.webkitRequestFullscreen) {
ele.webkitRequestFullscreen();
}
}

退出全屏方法为:

function exitfullScreen() { 
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.msExitFullscreen) {
document.msExitFullscreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.webkitExitFullscreen) {
document.webkitExitFullscreen();
}
}

综合方法为:

function fullscreen(ele,fn){
var fullscreenElement=document.webkitFullscreenElement||document.mozFullscreenElement||document.msFullscreenElement||document.FullscreenElement;
if(fullscreenElement){ //已经全屏
exitfullScreen();
}else{ //还未全屏

fullScreen(ele);
fn();
}
}

 var fullscreenElement=document.webkitFullscreenElement||document.mozFullscreenElement||document.msFullscreenElement||document.FullscreenElement;

为判断是否页面已经全屏

posted @ 2014-04-22 11:32  winenr123  阅读(371)  评论(0编辑  收藏  举报