Upgrade to Pro — share decks privately, control downloads, hide ads and more …

HTML5概览

Adam Lu
October 26, 2012

 HTML5概览

给某单位做的培训

Adam Lu

October 26, 2012
Tweet

More Decks by Adam Lu

Other Decks in Technology

Transcript

  1. Who am I • Software Engineer at Yahoo! R&D Beijing

    • 天地会HTML5/CSS3版版主 • 《YUI3 Cookbook》中文版译者 • 我的博客:http://adamlu.com • 我的微博:http://weibo.com/adamlu
  2. 时间轴 • 1995 Nov – HTML 2.0由IETF发布 • 1997 Jan

    – HTML3.2发布, W3C • 1997, Dec – HTML 4. • 1999, Dec – HTML 4.01发布. • 2000, Jan – XHTML 1.0 • 2001, May – XHTML 1.1
  3. WHATWG • W3C指定的标准完全理论化而与网站设计者的需 求无关 • 2004年,Ian Hickson提议扩展HTML来创建Web 应用程序 • 提议被否决

    • WHATWG形成(Web Hypertext Applications Working Group) • Ian Hickson成为HTML5的编辑 • 2006年,W3C采用了WHATWG所做的工作作为 基础重新统一了规范
  4. 语义化标签 • 很少的头代码 • 不需要type属性 <!DOCTYPE HTML> <html> <head> <meta

    charset=”utf-8”> <title>foo</title> </head> ... <script src=”foo.js”></script> <link href=”foo.css”></link>
  5. 语义化标签 Section: <article> <hgroup> <h1>Apples</h1> <h2>Tasty, delicious fruit!</h2> </hgroup> <p>The

    apple is the pomaceous fruit of the apple tree.</p> <section> <h1>Red Delicious</h1> <p>These bright red apples are the most common found in many supermarkets.</p> </section> <section> <h1>Granny Smith</h1> <p>These juicy, green apples make a great filling for apple pies.</p> </section> </article> Example: https://youzee.com/en/
  6. 语义化标签 <output name="result"></output> <progress id="p" max=100><span>0</span>%</progress> <meter value=6 max=8>6 blocks

    used (out of 8 total) </meter> Voter turnout: <meter value=0.75><img alt="75%" src="graph75.png"></meter> Tickets sold: <meter min="0" max="100" value="75"></meter>
  7. 语义化标签 Details和Summary: <details> <summary> Copying... <progress max="375505392" value="97543282"></progress> 25% </summary>

    <dl> <dt>Transfer rate:</dt> <dd>452KB/s</dd> <dt>Local filename:</dt> <dd>/home/rpausch/raycd.m4v</dd> </dl> </details>
  8. 语义化标签 Address: <address> <a href="../People/Raggett/">Dave Raggett</A>, <a href="../People/Arnaud/">Arnaud Le Hors</A>,

    contacts for the w3c HTML activity </address> Address 应用于最近的article或body标签
  9. 语义化标签 Data属性: <div class="spaceship" data-ship-id="92432" data- weapons="laser 2" data-shields="50%" data-x="30"

    data- y="10" data-z="90"><button class="fire"></div> <script> div = document.getElementsByTagName(‘ div’)[0]; spaceships[div.dataset.shipId].fire(); </script>
  10. 语义化标签 Figure和Figure标题: <figure> <img src="bubbles-work.jpeg" alt="Bubbles, sitting in his office

    chair, works on his latest project intently.“ /> <figcaption>Bubbles at work</figcaption> </figure>
  11. 语义化标签 Time和发布日期属性: <time pubdate datetime="2009-10-09T14:28- 08:00"></time> 菜单和命令: <menu type="toolbar"> <command

    type="radio" radiogroup="alignment" checked="checked" label="Left" icon="icons/alL.png" onclick="setAlign('left')"> <command type="radio" radiogroup="alignment" label="Center" icon="icons/alC.png" onclick="setAlign('center')"> <command type="radio" radiogroup="alignment" label="Right" icon="icons/alR.png" onclick="setAlign('right')"> </menu>
  12. 语义化标签 Mark用户高亮某些东西, <p><mark>Momentum is preserved across the wormhole. Electromagnetic radiation

    can travel in both directions through a wormhole, but matter cannot.</mark></p> 而Strong则是用来表示重要。 <p>When a wormhole is created, a vortex normally forms. <strong>Warning: The vortex caused by the wormhole opening will annihilate anything in its path.</strong></p>
  13. 语义化标签 Itemscope和Itemprop: <div itemscope> <p>My name is <span itemprop="name">Elizabeth</span>.</p> </div>

    <div itemscope> <p>My name is <span itemprop="name">Daniel</span>.</p> </div> <div itemscope> <p>My name is <span itemprop="name">Neil</span>.</p> <p>My band is called <span itemprop="band">Four Parts Water</ span>.</p> <p>I am <span itemprop="nationality">British</span>.</p> </div> http://jsfiddle.net/adamlu/vKurD/
  14. 图像处理 Canvas: <canvas id=”square”> fallback content </canvas> <script> var canvas

    = document.getElementById(‘square’); context = canvas.getContext(‘2d’); context.fillStyle = “#000000”; context.fillRect(0, 0, 100, 100); </script> Example: http://mudcu.be/sketchpad/
  15. 媒体支持 <audio src=”test.ogg”></audio> <audio src=”test.ogg” autoplay controls loop> <a href=”test.ogg”>download</a>

    </audio> <video controls/> <source src=”cat.mp4” /> <source src=”cat.ogg” /> </video> http://html5.grooveshark.com/ http://m.youtube.com/
  16. 设备支持 输入类型: <input type=”email” /> tel datetime search date email

    range url color 不支持的浏览器默认为text. DEMO: http://jquerymobile.com/demos/1.1.0-rc.1/docs/forms/textinputs/
  17. 设备支持 桌面通知: if (window.webkitNotifications.checkPermission() == 0) { // 0 is

    PERMISSION_ALLOWED window.webkitNotifications.createNotification('icon.png', 'Notification Title', 'Notification content...').show(); } else { window.webkitNotifications.requestPermission(); } http://jsfiddle.net/adamlu/neunM/
  18. 改善用户界面 拖拽: <div draggable=”true”></div> addEvent(div, “dragstart”, function(e){ e.dataTransfer.setData(‘foo’, ‘bar’); },

    true); addEvent(div, ‘dragend’, function(e){ e.dataTransfer.getData(‘foo’); }, true); 可编辑的内容—把一个元素变为可 编辑的区域 <script> document.getElementsByTagName ('p')[0].contentEditable = true; </script> DEMO: http://pi-squared.co.za/development/html5-touch/index.html
  19. 改善用户界面 History API: pushState(data, title [, url]); replaceState(data, title [,

    ulr]); window.addEventListener("popstate", function(e){ e.state; } Example: https://github.com/adamlu/yui3-cookbook
  20. 网络存储 Storage: sessionStorage.setItem(key, value); sessionStorage.getItem(key); localStorage.setItem(key, value); localStorage.getItem(key); localStorage.removeItem(key); 不再需要依赖Cookies,插件和针对浏览器的API

    Application Storage/Offline: <html manifest=”cache.manifest”> 检测online或offline window.addEventListener('online', online, true); window.addEventListener('offline', online, true); DEMO: http://www.webkit.org/demos/sticky-notes/
  21. 网络通信 跨域通信: postMessage(string); onMessage(event) { event.data; } Web Sockets: var

    ws = new WebSocket("ws://hostname:80/"); ws.onmessage = function (event) { event.data }; ws.onclose = function () {}; ws.onopen = function () {}; DEMO: http://html5demos.com/web-socket
  22. CSS3新特性 • 圆角 • 阴影 • 渐变 • 颜色 •

    背景 • 边框 • 字体 • 变换 • 过渡 • 动画 DEMO: http://jsfiddle.net/adamlu/xGuKy/
  23. 移动上的HTML5 • 移动网站在增长 • 移动用户在五年后会超过桌面网络用户 • 2016年之前将有21亿移动设备装有支持HTML5的 浏览器 • HTML5对于移动非常好

    • 不需要下载原生应用 • 同一套代码,发布到各个流行的设备上 • 大量的HTML5特性已经在移动浏览器上被支持
  24. Web App 和 Native App Web App Web App Web

    App Native App Native App Native App Comparation Comparation Comparation 只需要键入一个地址 必须被发布并下载 安装和更新 访问网站分析,基于SaaS 的增值策略 Apple Store, Google Play 获得价值 渐进增强 依照规范 终端体验 GeoLocation, Offline Storage, Canvas, Audio, Video, Camera 摄像头, 陀螺仪, 话筒, 指南 针, 加速计, GPS 访问硬件特性 HTML5, CSS3, Javascript, UI库 Object-C, Java, C++, J2EE, .NET, Cocoa Touch 开发者经验 Web Workers, 图像加速, WebGL 直接运行固件特性, GPU 加速, 多线程 性能
  25. 高级表单 <input type="number" pattern="[0-9]*" /> <input type="email” required /> <input

    type="url" /> <input type="tel" /> <input type="time" /> <input type="date" /> <input type="month" /> <input type="week" /> <input type="datetime" /> <input type="datetime-local" />
  26. JavaScript事件 window.addEventListener("touchstart", function(e){ //e.touches; }, false); window.addEventListener("orientationchange", function(e){ //window.orientation(0 is

    portrait, 90 and -90 are landscape) }, false); window.addEventListener("deviceorientation", function(e){ //e.alpha //e.beta //e.gamma }, false); window.addEventListener("devicemotion", function(e){ //e.acceleration.x/y/z //e.accelerationIncludingGravity.x/y/z }, false);
  27. CSS3媒体查询 @media screen and (max-width: 600px) { .class { background:

    #ccc; } .nav{display:none}; .dropdown-menu{display:block;} } @media screen and (min-width: 900px) { .class { background: red; } } @media screen and (max-device-width: 480px) { .class { background: 000; } } http://mediaqueri.es/
  28. 相关框架 • 模板:http://html5boilerplate.com/mobile • 打包工具: – http://phonegap.com/ – http://www.appmobi.com/ •

    应用程序框架: – http://jquerymobile.com/ – http://yuilibrary.com/ – http://sproutcore.com/ – http://www.sencha.com/ – http://zeptojs.com/ • HTML5游戏框架: – http://www.limejs.com/ – http://craftyjs.com/
  29. Mobile调试工具 • 调试: – WEINRE – WebKit Remote Debugging •

    模拟器: – Mobile Emulators and Simulators – Android Emulator – iOS Simulator • 性能监测: – Mobile PerfBookmarklet – http://www.blaze.io/mobile/
  30. 兼容性测试 • http://haz.io/ • http://caniuse.com/ • http://css3test.com/ • http://css3generator.com/ •

    http://css3info.com/ • http://html5test.com/ • http://css3please.com/ • http://mobilehtml5.org/ • http://quirksmode.org/m/