FreeABC
记忆重叠

用html5 js实现浏览器全屏

全屏

var docElm = document.documentElement;
//W3C  
if (docElm.requestFullscreen) {  
    docElm.requestFullscreen();  
}
//FireFox  
else if (docElm.mozRequestFullScreen) {  
    docElm.mozRequestFullScreen();  
}
//Chrome等  
else if (docElm.webkitRequestFullScreen) {  
    docElm.webkitRequestFullScreen();  
}
//IE11
else if (elem.msRequestFullscreen) {
  elem.msRequestFullscreen();
}

 

退出全屏

if (document.exitFullscreen) {  
    document.exitFullscreen();  
}  
else if (document.mozCancelFullScreen) {  
    document.mozCancelFullScreen();  
}  
else if (document.webkitCancelFullScreen) {  
    document.webkitCancelFullScreen();  
}
else if (document.msExitFullscreen) {
      document.msExitFullscreen();
}

事件监听

document.addEventListener("fullscreenchange", function () {  
    fullscreenState.innerHTML = (document.fullscreen)? "" : "not ";}, false);  
   
document.addEventListener("mozfullscreenchange", function () {  
    fullscreenState.innerHTML = (document.mozFullScreen)? "" : "not ";}, false);  
   
document.addEventListener("webkitfullscreenchange", function () {  
    fullscreenState.innerHTML = (document.webkitIsFullScreen)? "" : "not ";}, false);
document.addEventListener("msfullscreenchange", function () {
    fullscreenState.innerHTML = (document.msFullscreenElement)? "" : "not ";}, false);
全屏样式设置

 

全屏样式设置

html:-moz-full-screen {  
    background: red;  
}  
   
html:-webkit-full-screen {  
    background: red;  
}  
   
html:fullscreen {  
    background: red;  
}

 

附录

1 一个在线的Demo

    http://robnyman.github.io/fullscreen/

2   HTML5全屏API之网络钓鱼

      http://www.36ria.com/5807

3   jquery封装的全屏插件

     
Native Fullscreen JavaScript API (plus jQuery plugin)
4 更加详细的全屏API介绍 4.1 https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Using_full_screen_mode 4.2 https://dvcs.w3.org/hg/fullscreen/raw-file/tip/Overview.html 5 HTML5全屏API在FireFox/Chrome中的显示差异 http://www.zhangxinxu.com/wordpress/2012/10/html5-full-screen-api-firefox-chrome-difference/

 

未经允许不得转载:Free-Abc智能 » 用html5 js实现浏览器全屏
分享到: 更多 (0)