首页 > 其他 > 详细

功能0 -- fullscreen

时间:2019-02-23 15:20:20      阅读:167      评论:0      收藏:0      [点我收藏+]
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>fullscreen</title>
</head>
<body>
    <div id="content" style="width:500px;height:500px;">
      这是被全屏的元素
      <button id=‘btn‘>全屏</button>
      <button id="closeBtn">退出全屏</button>  
    </div> 

    <script type="text/javascript">
        let content = document.getElementById(‘content‘);   
        let openBtn = document.getElementById(‘btn‘);  
        let closeBtn = document.getElementById(‘closeBtn‘);  
        openBtn.onclick = function(){  
	    fullScreen(content);  
        }
        closeBtn.onclick = function(){  
            closeFullScreen();  
        }
	// 开启全屏
	function fullScreen(elem){
	  let docElm = document.documentElement;
	  if (docElm.requestFullscreen) {
	    // console.log(1)
	      docElm.requestFullscreen();  
	  } else if (docElm.mozRequestFullScreen) {
	    // console.log(2)
	      docElm.mozRequestFullScreen();  								//  firefox
	  } else if (docElm.webkitRequestFullScreen) {
	    // console.log(‘webkit内核‘)								//  chrome、360、QQ、遨游
	      docElm.webkitRequestFullScreen();  
	  } else if (docElm.msRequestFullscreen) {
	      // console.log(4)
	      elem.msRequestFullscreen();								//  IE
	  }
     }
	// 关闭全屏
	function closeFullScreen(){
	  if (document.exitFullscreen) {  
	    document.exitFullscreen();  
	  }else if (document.mozCancelFullScreen) {  
	    document.mozCancelFullScreen();  
	  }else if (document.webkitCancelFullScreen) {  
	    document.webkitCancelFullScreen();  
	  }else if (document.msExitFullscreen) {
	    document.msExitFullscreen();
	  }
     }
  </script>
</body>
</html>

  

功能0 -- fullscreen

原文:https://www.cnblogs.com/lgyong/p/10406197.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!