• h5的api dom全屏展示


    下面是完整的例子,暂不做分析

    <!DOCTYPE html>
    <html>
     <head>
      <title> FullScreen API 演示</title>
      <meta name="Generator" content="EditPlus">
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <meta name="Author" content="renfufei@qq.com">
      <meta name="Description" content="http://davidwalsh.name/more-html5-apis">
      <script>
    	// 处理全屏(需要全屏显示DOM元素)
    	function launchFullScreen(element) {
    	  // 先检测最标准的方法
    	  if(element.requestFullScreen) {
    		element.requestFullScreen();
    	  } else if(element.mozRequestFullScreen) {
    		// 其次,检测Mozilla的方法
    		element.mozRequestFullScreen();
    	  } else if(element.webkitRequestFullScreen) {
    		// if 检测 webkit的API
    		element.webkitRequestFullScreen();
    	  }
    	};
    	// 退出全屏,不用管具体是哪个元素,因为屏幕是唯一的。
    	function cancelFullscreen() {
    	  if(document.cancelFullScreen) {
    		document.cancelFullScreen();
    	  } else if(document.mozCancelFullScreen) {
    		document.mozCancelFullScreen();
    	  } else if(document.webkitCancelFullScreen) {
    		document.webkitCancelFullScreen();
    	  }
    	};
    	// 显示全屏信息
    	function dumpFullscreen() {
    		var d = document;
    		var fullE = null;
    		var fullEnable = "fullScreen is disable!";
    		if(d.fullScreenElement){
    			fullE = d.fullScreenElement;
    		} else if(d.mozFullScreenElement){
    			// 如果有问题,把mozFullscreenElement 改为 mozFullScreenElement,S大写
    			fullE = d.mozFullScreenElement;
    		} else if(d.webkitFullscreenElement){
    			// 本人的为chrome, Fullscreen 之中,s为小写。
    			fullE = d.webkitFullscreenElement;
    		}
    		// 如果有问题,请切换 fullScreen 中 s 的大小写。
    		if(d.fullScreenEnabled){
    			fullEnable = d.fullScreenEnabled;
    		} else if(d.mozFullScreenEnabled){
    			fullEnable = d.mozFullScreenEnabled;
    		} else if(d.webkitFullscreenEnabled){
    			// 注意 Fullscreen 的中间s大小写
    			fullEnable = d.webkitFullscreenEnabled;
    		}
    		//
    		if(window.console){
    			console.dir(fullE);
    		} else if(fullE){
    			alert(fullE.tagName);
    		} else {
    			alert("全屏元素是:"+fullE);
    		}
    		//
    		if(window.console){
    			console.info("允许全屏:"+fullEnable);
    		} else if(fullEnable){
    			alert("允许全屏:"+fullEnable);
    		} else {
    			alert("允许全屏:"+fullEnable);
    		}
    	};
    	// 设置事件监听,DOM内容加载完成,和jQuery的$.ready() 效果差不多。
    	window.addEventListener("DOMContentLoaded", function() {
    		// 获取DOM元素
    		var enterfull = document.getElementById("enterfull");
    		var quitfull = document.getElementById("quitfull");
    		var dumpfull = document.getElementById("dumpfull");
    			
    		// 事件监听
    		enterfull.addEventListener("click", function() {
    			// 
    			launchFullScreen(document.documentElement);
    		});
    		quitfull.addEventListener("click", function() {
    			// 
    			cancelFullscreen();
    		});
    		dumpfull.addEventListener("click", function() {
    			// 
    			dumpFullscreen();
    		});
    
    	}, false);
    	// 全屏事件Events
    	document.addEventListener("fullscreenchange", function(e) {
    	  console.dir(e);
    	});
    	document.addEventListener("mozfullscreenchange", function(e) {
    	  console.dir(e);
    	});
    	document.addEventListener("webkitfullscreenchange", function(e) {
    	  console.dir(e);
    	});
      </script>
     </head>
    
     <body>
      
    	<div>
    		<button id="enterfull">进入全屏</button><br/>
    		<button id="quitfull">退出全屏</button><br/>
    		<button id="dumpfull"> 查看全屏的DOM元素</button><br/>
    	</div>
     </body>
    </html>
    

      

    耐得住寂寞,守得住繁华
  • 相关阅读:
    html5 鼠标跟随运动
    2018新年计划
    background-attachment:fixed不兼容性
    Javascript中常用方法简介
    FQ教程真实好用
    解决IE6 IE7绝对定位弹层被后面的元素遮住
    页面出现滚动条时,body里面的内容不能自动居中?
    怎么查看手机源码
    ES6入门教程---数值扩展和数组扩展
    ES6入门教程---解构赋值和字符串扩展
  • 原文地址:https://www.cnblogs.com/djdliu/p/5028592.html
Copyright © 2020-2023  润新知