Deep Dive into “HTML5”

11/22/2010

閱讀時間 6 分鐘

本文內容

How do I develop using Canvas, SVG, CSS3? What’s new in JavaScript? In this deep dive you will learn how to use HTML5 and how new web standards help solve existing challenges on the web. Expect a lot of code, demos, and best practices!

Video, Slides, and Links

3582.clip_image0015_49FD9D82.png

Covered in the session…

HTML5 Markup

How do you start an HTML5 page? Actually HTML5 is evolutionary, not revolutionary. Any page built yesterday with HTML 4.1 will be an HTML5 page automatically tomorrow. However, the HTML5 specification provides a few optional changes that can simplify your markup. For example, the following code is what I use as a template for my new pages.

HTML5 also provides a set of new tags (for example, , , and

) that adds more semantic meaning to the content, and helps accessibility tools (such as screen readers) and search engines to better understand the page.

1050.image_705C4F07.pngThe tag is probably one of the most interesting (and most discussed) new tags in the HTML5 markup language. It allows you to embed a video on the page without using a plug-in. The samples I provide explain how to use its properties (for example, poster to define the initial frame, or controls to show the control buttons, or preload to set the pre-fetching rules). As we’ve seen, the current specification doesn’t allow the player to go full-screen. If you need this scenario, you can change the size of the control dynamically and bring it on top of the page using the zIndex. Through its events loadedmetadata, canplay, and timeupdate you can monitor when the video is ready to play and track its progress. Lastly, the canPlayType property allows you to test whether the UA supports a specific codec or container; remember, the return values are either “”, “maybe”, or “probably”.

1018.wlEmoticon-winkingsmile_43A6A127.png

1070.image4_thumb_0495835F.pngDrawing on a page has never been so easy. You have a brush that you can move across the screen to draw images – that’s all you need in order to create amazing drawings or animations! If you are drawing an image, remember to wait for it to be loaded. When you develop an animation, you will need to decide the best strategy to serve your purpose. Use time-based animation if you need a precise, smooth, and predictable result. Use frame-based animation if you need to develop quickly and are comfortable with losing some cycles (timer resolution is not perfect!).

With a little bit of creativity, you can achieve quite interesting scenarios – for instance, drawing a video on a canvas and dynamically appending its mirrored shadow.

ctx.translate(0, 200);

ctx.scale(1, -1); // Flip video

// Prepare gradient

var gradient = ctx.createLinearGradient(0, 0, 0, canvas.height);

gradient.addColorStop(0, "rgba(255,255,255,255)");

gradient.addColorStop(1, "rgba(255,255,255,0)");

ctx.fillStyle = gradient;

myVideo.addEventListener('canplay', function () {

setInterval(function () {

ctx.drawImage(myVideo, 0, 0, 300, 200); // Draw video frame

ctx.fillRect(0, 0, 640, 360); // Draw fading

}, 60);

}, false);

7532.image_39BE7DF6.pngIf you are looking for a tool to design on canvas or to design prototype animations, check out the AI2Canvas Exporter plug-in built by our own Mike Swanson. You can achieve great results with it – for instance, take a look at what Joshua Davis did!

In this group of demos, you will also find a little game I built on the plane while I was flying to Berlin. I’ll get back to this in a future post.

SVG

7357.image_thumb_3D5C98D3.pngSVG (Scalable Vector Graphics) adds even more capabilities to what you can achieve with the Canvas. This time you are dealing with objects, which have their own properties, events, and programmability. You can embed your SVG snippets inline in an HTML page (did you know Internet Explorer 9 is the first browser to support this?), or embed in an XHTML document, as well as standalone files or files that are referenced inside an tag.

SVG is intrinsically designed to work with the rest of the standards. You can program it using JavaScript and the APIs that you already know; and you can style it using CSS!

The last demo (Gradients) is a prototype of SVG+CSS+HTML5+JavaScript in action. Using a few tricks, you can use SVG to build a color gradient dynamically and use CSS properties to apply it to any HTML element on the page. I had some interesting conversations with Jonathan and Robert about this approach – I think it might be interesting to explore it further. eCSStender from Aaron Gustafson seems to be the natural evolution of the prototype; please ping me if you are interested in further exploring this approach with me!

CSS3

2158.image_thumb_18CB0B4F.png

What about news for web designers? CSS3 brings a lot of new and interesting modules to the table. Of all of them, text/border shadows, colors (rgba, opacity), multiple backgrounds, border radius, media queries, and WOFF are the ones I believe to be the most stable today.

@font-face

{

font-family: '3DumbRegular';

src: local('☺'), url('WOFF/3Dumb-webfont.woff') format('woff');

font-weight: normal;

font-style: normal;

}

.fontface

{

font: 60px/68px '3DumbRegular' , Arial, sans-serif;

letter-spacing: 0;

}

Run the demo, “1. Media Queries” to understand how CSS allows you to pick specific rules depending on the screen resolution. Plus, you can have some fun with my hand (seriously – that’s my hand, copyright at Giorgio Sardo

1031.wlEmoticon-thumbsup_18620A20.png).

ECMA

Last but not least, JavaScript has some very neat new features for developers! For example, it includes a native JSON object that allows you to accomplish serialization/deserialization operations very quickly, that in the past you probably did with external libraries.

var result;

var myArray = new Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);

//NEW! forEach

var multiply = function (value, index, array) { array[index] = value * this };

/* No Return! */ myArray.forEach(multiply, 3);

//result= 3, 6, 9, 12, 15, 18, 21, 24, 27, 30

There are a lot of new Array methods that simplify common tasks such as looping through the Array and performing a particular operation. I personally love the ability to do “kind of lambda expression” using forEach().

The object model has also evolved. With the new syntax, Object.create can more easily define new and cleaner prototypes.

Lastly, you finally have access to some helper functions, such as Date.Parse() and String.Trim().

Conclusion

This is not an extensive coverage of all the new features of HTML5 and related web standards. There is much more in the pipeline (Robert talked more about this)! What I covered in this session is probably the most mature content in the specification. It is (or soon will be) available across all the major browsers. It’s interoperable and it doesn’t apply only to Internet Explorer 9…but to any browser. In other words, it’s ready!

1524.wlEmoticon-hotsmile_7127C0EA.png

You can download all the source code here. Please feel free to contact me if you have any feedback or questions – I’m sure somebody out there knows how to improve this!

html5 mature,Deep Dive into “HTML5”相关推荐

  1. html5声明doctype,html-声明HTML5 Doctype的正确方法是什么。

    html-声明HTML5 Doctype的正确方法是什么. 使用HTML5创建时使用开始标记的正确方法是什么 IE:HTML 4 Strict就是这样 user6573 asked 2020-07-2 ...

  2. html5发展前景-兄弟连,IT兄弟连 HTML5教程 HTML5的曲折发展过程 HTML5的诞生

    原标题:IT兄弟连 HTML5教程 HTML5的曲折发展过程 HTML5的诞生 十年磨一剑,正如我们所看到的一样,HTML5大潮正来势汹汹.但也正如我们所知道的一样,HTML5是一种技术标准,它的语义 ...

  3. html5交互效果,浅谈HTML5 CSS3的新交互特性

    本文标题的这副图片,是用Phosotshop制作的.但是,在搜索引擎中你却无法搜索到它,搜索引擎还没有强大到能够识别图片里面的文字.并且由于图片的体积不算太小,可能网速慢的网友在浏览的时候不得不耐心的 ...

  4. html5 的menu的属性,HTML5 menu 标签

    实例 HTML5 两个菜单按钮系列选项实例("File" 和 "Edit"): New... Open... Save Cut Copy Paste 尝试一下 ...

  5. html5通过api调数据库,使用HTML5数据库API [关闭](Using HTML5 Database API [closed])

    使用HTML5数据库API [关闭](Using HTML5 Database API [closed]) 我正在开发一个使用phonegap/cordova 2.2的web应用程序,并希望将数据存储 ...

  6. HTML5/CSS3系列教程:HTML5 区域(Sectioning)的重要性

    日期:2013-2-4  来源:GBin1.com 不管你以前在web页面布局中如何称呼它们 - "区域"还是"块",我们一直都在布局中将页面分成可视的不同区域 ...

  7. html5标签属性大全_HTML/HTML5 知识点思维导图

    HTML 1 - 浏览器 | 浏览器页面构成 2 - 浏览器 | 浏览器内核相关知识点 3 - W3C | 对WEB标准以及W3C的理解与认识? 4 - 标签 | Doctype相关知识点 5 - 标 ...

  8. 重磅解读:K8s Cluster Autoscaler模块及对应华为云插件Deep Dive

    背景信息 基于业务团队(Cloud BU 应用平台)在开发Serverless引擎框架的过程中完成的K8s Cluster Autoscaler华为云插件. 目前该插件已经贡献给了K8s开源社区,见下 ...

  9. html5画图论文结束语,基于HTML5 Canvas的画图板的设计与实现.doc

    单片机论文_优秀毕业论文_毕业论文设计_毕业过关论文_毕业设计_毕业设计说明_毕业论文_单片机毕业论文_基于单片机毕业论文_毕业论文终稿_毕业论文初稿_毕业论文设计_单片机论文_本文档支持完整下载,支 ...

  10. html5的canvas动画,Canvas HTML5简介 · Canvas动画教程

    Ch1 HTML5简介 前言 今后的一个月内会连载详细的Canvas教程,从零基础开始,到Canvas API,再到基本动画与高级动画的实现,还会介绍视音频的处理.移动应用,最后如果有时间会扩展说一说 ...

最新文章

  1. 如何优雅的使用 Angular 表单验证
  2. 谨慎跟随初始目的不被关联问题带偏
  3. 06.Spring 资源加载 - ResourceLoader
  4. 【AC Saber】离散化
  5. 最小熵原理系列:词向量的维度应该怎么选择?
  6. MAC 更新 PHP 指南 以及 PHP常用命令示例
  7. opencart卸载语言包要记得在后台进行设置否则会出错
  8. Veeam创建复制任务Replication Job
  9. Theano中的Function
  10. spark学习-scala版写的SparkSQL程序读取Hbase表注册成表SQL查询
  11. C语言线程创建与锁机制
  12. Apollo的学习笔记
  13. spss标准差与标准偏差不一样
  14. OpenXML:C#操作PPT文档
  15. java eml_javamail读取并解析eml文件
  16. CVPR 2022 Oral | 视频文本预训练新SOTA!港大腾讯推出基于多项选择题的借口任务...
  17. 耐压测试仪结构组成部分
  18. Animate.css动画
  19. 量化交易 米筐 因子分组打分(成长因子)
  20. 2021年中式烹调师(中级)考试内容及中式烹调师(中级)新版试题

热门文章

  1. wordpress中文路径出现404错误的解决办法
  2. 题解(1-4)-----寒假练习赛(一)
  3. iosmask_iOS Mask属性的详细介绍及应用实例_IOS_脚本之家
  4. mysql text 性能_MySQL - text 性能优化--记录一
  5. 戴尔optiplex3020主板接线_戴尔XPS 13 2020上手,12999元的高端精致怪,让苹果也很有压力!...
  6. php对接海康视频教程_手把手教你php对接海康api
  7. 删除java速度变慢_Java正则表达式运行速度很慢
  8. html图表实现,用 Flotr2 实现的 HTML5 图表
  9. 翻译: Swift 中的委托保留周期 如何在“纯”Swift(没有@objc)中进行弱协议引用
  10. Google Code Review 处理代码审查中的推回