本文来自:http://www.myext.cn/webkf/18457.html
1.Canvas
顾名思义,画布,你在上面画画
<!DOCTYPE html>
<html>
<canvas id="canvas" style="border: 1px solid;" width="250" height="250"> </canvas>
<script>
function drawTriangle(context){//画三角形
context.beginPath();
context.moveTo(0, 0);
context.lineTo(30, -30);
context.lineTo(60, 0);
context.lineTo(0, 0);
context.fillStyle = '#339900';
context.fill();
context.closePath();
}
function draw() {
var canvas = document.getElementById('canvas');//获取画布
var context = canvas.getContext('2d');//获取画笔
context.save();
context.translate(30, 60);//移动基准位置
drawTriangle(context);//画第一个三角形
context.stroke();
context.translate(60, 90);//移动基准位置
drawTriangle(context);//画第二个三角形
context.stroke();
context.restore();
}
window.addEventListener("load", draw, true);
</script>
</html>
在浏览器里的样子
2.Audio/Video
无需插件,播放音频,视频,每个浏览器能支持的格式不一样,自己掂量吧
!DOCTYPE html>
<html>
<audio controls>
<source src="johann_sebastian_bach_air.ogg">
<source src="johann_sebastian_bach_air.mp3">
An audio clip from Johann Sebastian Bach.
</audio>
</html>
Chrome中Audio的样子
如何在JS中控制Audio的播放
<!DOCTYPE html>
<html>
<audio id="clickSound">
<source src="johann_sebastian_bach_air.ogg">
<source src="johann_sebastian_bach_air.mp3">
</audio>
<button id="toggle" onclick="toggleSound()">Play</button>
<script type="text/javascript">
function toggleSound() {
var music = document.getElementById("clickSound");
var toggle = document.getElementById("toggle");
if (music.paused) {
music.play();
toggle.innerHTML = "Pause";
}
else {
music.pause();
toggle.innerHTML ="Play";
}
}
</script>
</html>
Video播放和控制
<!DOCTYPE html>
<html>
<video id="movies" controls onmouseover="this.play()" onmouseout="this.pause()" autobuffer="true"
width="400px" height="300px">
<source src="Intermission-Walk-in.ogv" type='video/ogg; codecs="theora, vorbis"'>
<source src="Intermission-Walk-in_512kb.mp4" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"'>
</video>
</html>
Chrome中Video的样子
3.Geolocation
获取用户地理位置,用户可以选择是否愿意,目前来说相当的不靠谱,fanqiang后可以在Firefox测试成功,因为Firefox使用的Google的地理服务,看看代码,也比较简单
<script type="text/javascript">
function loadDemo() {
if(navigator.geolocation) {//检测浏览器是否支持Geolocation
navigator.geolocation.getCurrentPosition(updateLocation);
}
}
function updateLocation(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
if (!latitude || !longitude) {
return;
}
document.getElementById("latitude").innerHTML = latitude;
document.getElementById("longitude").innerHTML = longitude;
}
</script>
分享到:
相关推荐
html5入门代码大全(源码) 包含audio、video、canvas 、communication、forms、geolocation、intro、offline、storage、websocket、workers
HTML5新增和移除的元素 HTML5基本布局 HTML5对表单的支持 HTML5 DOM变化 HTML5的Javascript APIs Canvas Video/Audio Drag&Drop Geolocation Application Cache Database Storage X-Document Messaging
为读者清晰解读了HTML5规范的缘由、发展和现状,全面展示了如何使用 WebSocket、Geolocation、Web Storage、Canvas及音频视频等前所未有的新特性构建先进的Web应用,并以大量的示例涵盖全部HTML5 API。此外,还介绍...
为读者清晰解读了HTML5规范的缘由、发展和现状,全面展示了如何使用 WebSocket、Geolocation、Web Storage、Canvas及音频视频等前所未有的新特性构建先进的Web应用,并以大量的示例涵盖全部HTML5 API。此外,还介绍...
从第2 章起,分别围绕构建令人神往的富web 应用,逐一讨论了html5 的canvas、geolocation 、communication、websocket、forms、web workers、storage 等api 的使用, 辅以直观明了的客户端和服务器端示例代码,让...
为读者清晰解读了HTML5规范的缘由、发展和现状,全面展示了如何使用 WebSocket、Geolocation、Web Storage、Canvas及音频视频等前所未有的新特性构建先进的Web应用,并以大量的示例涵盖全部HTML5 API。此外,还介绍...
为读者清晰解读了HTML5规范的缘由、发展和现状,全面展示了如何使用 WebSocket、Geolocation、Web Storage、Canvas及音频视频等前所未有的新特性构建先进的Web应用,并以大量的示例涵盖全部HTML5 API。此外,还介绍...
HTML5和css3入门开发资料 HTML5新增和移除的元素 HTML5基本布局 HTML5对表单的支持 HTML5 DOM变化 ...Video/Audio Drag&Drop; Geolocation Application Cache Database Storage X-Document Messaging
为读者清晰解读了HTML5规范的缘由、发展和现状,全面展示了如何使用 WebSocket、Geolocation、Web Storage、Canvas及音频视频等前所未有的新特性构建先进的Web应用,并以大量的示例涵盖全部HTML5 API。此外,还介绍...
为读者清晰解读了HTML5规范的缘由、发展和现状,全面展示了如何使用 WebSocket、Geolocation、Web Storage、Canvas及音频视频等前所未有的新特性构建先进的Web应用,并以大量的示例涵盖全部HTML5 API。此外,还介绍...
为读者清晰解读了HTML5规范的缘由、发展和现状,全面展示了如何使用 WebSocket、Geolocation、Web Storage、Canvas及音频视频等前所未有的新特性构建先进的Web应用,并以大量的示例涵盖全部HTML5 API。此外,还介绍...
为读者清晰解读了HTML5规范的缘由、发展和现状,全面展示了如何使用 WebSocket、Geolocation、Web Storage、Canvas及音频视频等前所未有的新特性构建先进的Web应用,并以大量的示例涵盖全部HTML5 API。此外,还介绍...
为读者清晰解读了HTML5规范的缘由、发展和现状,全面展示了如何使用 WebSocket、Geolocation、Web Storage、Canvas及音频视频等前所未有的新特性构建先进的Web应用,并以大量的示例涵盖全部HTML5 API。此外,还介绍...
从第 2章起,分别围绕构建令人神往的富Web 应用,逐一讨论了HTML5的Canvas、Geolocation、Communication、WebSocket、Forms、WebWorkers、Storage等API的使用,辅以直观明了的客户端和服务器端示例代码,让开发人员...
How to develop cutting-edge web applications using new HTML5 features like WebSockets, geolocation, web storage, Canvas, and audio/video Which features are available in modern browsers
APIs: The Geolocation API Chapter 29. APIs: Server Sent Events Chapter 30. APIs: The WebSocket API Chapter 31. APIs: The Cross-document Messaging API Book Details Paperback: 250 pages Publisher: ...
3 Audio and video controls 66 4 Canvas 90 5 The History API: Changing the game for MVC sites 118 6 Geolocation and web mapping 147 7 Web workers and drag and drop 185 8 Websockets 214 9 Local storage ...
You get clear solutions for handling issues with everything from markup semantics, web forms, and audio and video elements to related technologies such as geolocation and rich JavaScript APIs. ...
* How to develop cutting-edge web applications using new HTML5 features like WebSockets, Geolocation, Web Storage, Canvas, and Audio and Video. * Which features are available in browsers today ...
一本很好的HTML5开发的教程 Browser support: What you can (and can’t) do with HTML5 today HTML5 document structure and semantics Intelligent forms, including new input types, elements, and client-side ...