The birth of HTML5 has provided us with many wonderful new functions and features of JavaScript and HTML. Some of the new features have been known to us for years and are used extensively, while others are primarily used in cutting-edge mobile technologies, or as auxiliary functions in desktop applications. No matter how powerful and easy-to-use these new HTML5 features are, they are all designed to help us better develop browser front-end applications. I have previously shared with you an article about 5 new HTML5 features that you don’t know about. I hope that some of the technologies mentioned in it can help improve your web applications. Here I also want to share with you some new HTML5 features that few people know about. I hope they can be of some use to you!
1. Full-screen API interface
The powerful full-screen API interface allows programmers to launch the browser into full-screen mode through programming and request the user's permission:
// Launch fullscreen for browsers that support it!
launchFullScreen(document.documentElement); // the whole page
launchFullScreen(document.getElementById("videoElement")); // any individual element
2. Page visibility API interface
The page visibility API interface provides a listening event. This event can tell the programmer whether the current page is a tab/window activated in the browser and whether it is the page the user is watching. It can also tell the program When to switch pages and stop viewing this page/window:
// Add a listener that constantly changes the title
document.addEventListener(visibilityChange, function(e) {
// Start or stop processing depending on state
}, false);
3. getUserMedia interface API
getUserMedia API is a very interesting interface! Using this API and adding the
// Put video listeners into place
if(navigator.getUserMedia) { // Standard
navigator.getUserMedia(videoObj, function(stream) {
video.src = stream;
video.play();
}, errBack);
} else if(navigator.webkitGetUserMedia) { // WebKit-prefixed
navigator.webkitGetUserMedia(videoObj, function(stream){
video.src = window.webkitURL.createObjectURL(stream);
video.play();
}, errBack);
}
}, false);
四、电池接口API
电池接口API很显然是专门为手机里的浏览器应用设计的,它提供了读取设备里的电池电量和充电状态的功能:
// A few useful battery properties
console.warn("Battery charging: ", battery.charging); // true
console.warn("Battery level: ", battery.level); // 0.58
console.warn("Battery discharging time: ", battery.dischargingTime);
// Add a few event listeners
battery.addEventListener("chargingchange", function(e) {
console.warn("Battery charge change: ", battery.charging);
}, false);
五、页面预加载(Link prefetch)API
页面预加载(Link prefetch)API功能能够让浏览器在后台静悄悄的预先加载/读取一些页面或资源到当前页面,给用户一个顺滑的使用体验:
就是这5个你需要知道和尝试的新HTML5 API。请注意,这些新功能在几年之内就会流行起来,所以,越早接受这些API,你就能更好的创造出最前沿技术的Web应用。花几分钟试试这些新功能,看看你能用它们实现什么样的效果!