| 
                        [backcolor=rgb(248, 248, 248) !important]1 2 [backcolor=rgb(248, 248, 248) !important]3 4 [backcolor=rgb(248, 248, 248) !important]5 6 [backcolor=rgb(248, 248, 248) !important]7 8 [backcolor=rgb(248, 248, 248) !important]9 10 [backcolor=rgb(248, 248, 248) !important]11 12 [backcolor=rgb(248, 248, 248) !important]13 14 | [backcolor=rgb(248, 248, 248) !important]// 根据目标元素调用相应的方法function launchFullScreen(element) {
 [backcolor=rgb(248, 248, 248) !important] if(element.requestFullScreen) {
 element.requestFullScreen();
 [backcolor=rgb(248, 248, 248) !important] } else if(element.mozRequestFullScreen) {
 element.mozRequestFullScreen();
 [backcolor=rgb(248, 248, 248) !important] } else if(element.webkitRequestFullScreen) {
 element.webkitRequestFullScreen();
 [backcolor=rgb(248, 248, 248) !important] }
 }
 
 // 在支持的浏览器中启动全屏
 [backcolor=rgb(248, 248, 248) !important]launchFullScreen(document.documentElement); // 整个页面
 launchFullScreen(document.getElementById("videoElement")); // 单个元素
 
 
 
 
 Page Visibility API
   Page Visibility API 可以帮助开发者监听用户的焦点在哪个页面选项卡上面以及用户在选项库或者窗口之间的移动情况。如果使用合理的话,当焦点不在某个页面上的时候可以停止一些消耗很大的任务。[size=1em] [color=rgb(255, 255, 255) !important]?  
 
                            
                                
                                    | 
                                    [backcolor=rgb(248, 248, 248) !important]1 2 [backcolor=rgb(248, 248, 248) !important]3 4 [backcolor=rgb(248, 248, 248) !important]5 6 [backcolor=rgb(248, 248, 248) !important]7 8 [backcolor=rgb(248, 248, 248) !important]9 10 [backcolor=rgb(248, 248, 248) !important]11 12 [backcolor=rgb(248, 248, 248) !important]13 14 [backcolor=rgb(248, 248, 248) !important]15 16 [backcolor=rgb(248, 248, 248) !important]17 18 [backcolor=rgb(248, 248, 248) !important]19 20 [backcolor=rgb(248, 248, 248) !important]21 22 [backcolor=rgb(248, 248, 248) !important]23 24 [backcolor=rgb(248, 248, 248) !important]25 | [backcolor=rgb(248, 248, 248) !important]// 部分浏览器只支持 vendor-prefixed// 根据浏览器支持情况设置隐藏属性和可见状态改变事件
 [backcolor=rgb(248, 248, 248) !important]var hidden, state, visibilityChange;
 if (typeof document.hidden !== "undefined") {
 [backcolor=rgb(248, 248, 248) !important] hidden = "hidden";
 visibilityChange = "visibilitychange";
 [backcolor=rgb(248, 248, 248) !important] state = "visibilityState";
 } else if (typeof document.mozHidden !== "undefined") {
 [backcolor=rgb(248, 248, 248) !important] hidden = "mozHidden";
 visibilityChange = "mozvisibilitychange";
 [backcolor=rgb(248, 248, 248) !important] state = "mozVisibilityState";
 } else if (typeof document.msHidden !== "undefined") {
 [backcolor=rgb(248, 248, 248) !important] hidden = "msHidden";
 visibilityChange = "msvisibilitychange";
 [backcolor=rgb(248, 248, 248) !important] state = "msVisibilityState";
 } else if (typeof document.webkitHidden !== "undefined") {
 [backcolor=rgb(248, 248, 248) !important] hidden = "webkitHidden";
 visibilityChange = "webkitvisibilitychange";
 [backcolor=rgb(248, 248, 248) !important] state = "webkitVisibilityState";
 }
 
 // 添加一个时间来实时改变页面的标题
 [backcolor=rgb(248, 248, 248) !important]document.addEventListener(visibilityChange, function(e) {
 // Start or stop processing depending on state
 [backcolor=rgb(248, 248, 248) !important]}, false);
 
 
 |  
 
 Supporting visibilityChange in MooTools
 MooTools doesn't support visibilityChange out of the box, so you'll need to add this bit of JavaScript:// Set it up!Element.NativeEvents[visibilityChange] = 2;Element.Events[visibilityChange] = { base: visibilityChange, condition: function(event) { event[state] = document[state]; event.visibilityState = document[state]; return true; }};// Now use it!document.addEvent(visibilityChange, function(e) { document.title = document[state];}); Don't you love it when it's that easy?! This mirror the code needed to add onMessage events to the list of supported events. getUserMedia API
   特别有趣的一个 API,能够调用电脑的摄像头,结合 <video> 标签和 Canvas 就能在浏览器中拍摄照片了。未来这个 API 将被广泛用来让浏览器和用户之间互动。[size=1em] [color=rgb(255, 255, 255) !important]?  
 
                            
                                
                                    | 
                                    [backcolor=rgb(248, 248, 248) !important]1 2 [backcolor=rgb(248, 248, 248) !important]3 4 [backcolor=rgb(248, 248, 248) !important]5 6 [backcolor=rgb(248, 248, 248) !important]7 8 [backcolor=rgb(248, 248, 248) !important]9 10 [backcolor=rgb(248, 248, 248) !important]11 12 [backcolor=rgb(248, 248, 248) !important]13 14 [backcolor=rgb(248, 248, 248) !important]15 16 [backcolor=rgb(248, 248, 248) !important]17 18 [backcolor=rgb(248, 248, 248) !important]19 20 [backcolor=rgb(248, 248, 248) !important]21 22 [backcolor=rgb(248, 248, 248) !important]23 24 | [backcolor=rgb(248, 248, 248) !important]// 添加事件监听器window.addEventListener("DOMContentLoaded", function() {
 [backcolor=rgb(248, 248, 248) !important] // 获取元素,创建配置
 var canvas = document.getElementById("canvas"),
 [backcolor=rgb(248, 248, 248) !important] context = canvas.getContext("2d"),
 video = document.getElementById("video"),
 [backcolor=rgb(248, 248, 248) !important] videoObj = { "video": true },
 errBack = function(error) {
 [backcolor=rgb(248, 248, 248) !important] console.log("Video capture error: ", error.code);
 };
 
 // 添加视频监听器
 [backcolor=rgb(248, 248, 248) !important] if(navigator.getUserMedia) { // 标准的API
 navigator.getUserMedia(videoObj, function(stream) {
 [backcolor=rgb(248, 248, 248) !important] video.src = stream;
 video.play();
 [backcolor=rgb(248, 248, 248) !important] }, errBack);
 } else if(navigator.webkitGetUserMedia) { // WebKit 核心的API
 [backcolor=rgb(248, 248, 248) !important] navigator.webkitGetUserMedia(videoObj, function(stream){
 video.src = window.webkitURL.createObjectURL(stream);
 [backcolor=rgb(248, 248, 248) !important] video.play();
 }, errBack);
 [backcolor=rgb(248, 248, 248) !important] }
 }, false);
 
 
 |  
 
 Battery API
   顾名思义,这是一个电池 API ,明显是为移动设备准备的,用于监控电池的状态。能够通过事件监听电池电量的变化,电池的等级、可用时间等状态。下面是是示例代码,可以通过后面的教程链接学习更详细的使用方法。[size=1em] [color=rgb(255, 255, 255) !important]?  
 
                            
                                
                                    | 
                                    [backcolor=rgb(248, 248, 248) !important]1 2 [backcolor=rgb(248, 248, 248) !important]3 4 [backcolor=rgb(248, 248, 248) !important]5 6 [backcolor=rgb(248, 248, 248) !important]7 8 [backcolor=rgb(248, 248, 248) !important]9 10 [backcolor=rgb(248, 248, 248) !important]11 12 | [backcolor=rgb(248, 248, 248) !important]// 获取电池对象var battery = navigator.battery || navigator.webkitBattery || navigator.mozBattery;
 
 // 一组非常有用的电池属性
 [backcolor=rgb(248, 248, 248) !important]console.warn("Battery charging: ", battery.charging); // true
 console.warn("Battery level: ", battery.level); // 0.58
 [backcolor=rgb(248, 248, 248) !important]console.warn("Battery discharging time: ", battery.dischargingTime);
 
 [backcolor=rgb(248, 248, 248) !important]// 监听电池状态
 battery.addEventListener("chargingchange", function(e) {
 [backcolor=rgb(248, 248, 248) !important] console.warn("Battery charge change: ", battery.charging);
 }, false);
 
 
 |  
 
 Link Prefetching
   这个链接预取 API 非常有用,让开发者可以控制网页资源在后台安静的预先加载,这样用户在浏览网站或者使用 Web 应用程序的时候能够有流畅的使用体验。可以预加载整个页面,也可以是单个资源,示例代码如下:[size=1em] [color=rgb(255, 255, 255) !important]?  
 
                            
                                
                                    | 
                                    [backcolor=rgb(248, 248, 248) !important]1 2 [backcolor=rgb(248, 248, 248) !important]3 4 [backcolor=rgb(248, 248, 248) !important]5 |  |  
 
 
   上面这5个 HTML5 API 值得关注,在不久的将来这些 API 将被广泛的使用,因此越早掌握它们可以帮助你为构建优秀的 Web 应用打下坚实的基础。通过使用教程可以快速的熟悉这些 API 的基本用法和使用场景,提供的在线演示展示了直观的应用情况。 |