SlideShare una empresa de Scribd logo
1 de 34
Descargar para leer sin conexión
Short	
  intro	
  to	
  HTML5	
  

            Jussi	
  Pohjolainen	
  
Tampere	
  University	
  of	
  Applied	
  Sciences	
  
HTML5	
  
•  Fi#h	
  version	
  of	
  HTML	
  standard	
  by	
  W3C	
  
•  SCll	
  under	
  development	
  but	
  lot	
  of	
  browsers	
  
   support	
  the	
  proposal	
  of	
  the	
  standard	
  
•  Simple	
  markup	
  that	
  can	
  be	
  wriFen	
  either	
  in	
  
   HTML	
  or	
  XHTML	
  syntax	
  
•  PotenCal	
  candidate	
  for	
  cross	
  pla0orm	
  mobile	
  
   apps	
  
HTML5	
  
•  "Replacement	
  for	
  Flash"	
  
    –  See	
  comparison:	
  	
  
        •  hFp://en.wikipedia.org/wiki/
           Comparison_of_HTML5_and_Flash	
  
•  HTML5	
  must	
  be	
  supplemented	
  with	
  other	
  
   technologies	
  like	
  CSS3	
  and	
  JS	
  
    –  HTML5	
  recommendaCon	
  specifies	
  html	
  markup	
  and	
  
       APIs	
  for	
  that	
  can	
  be	
  used	
  with	
  JS	
  
•  Plan	
  is	
  to	
  have	
  HTML5	
  recommendaCon	
  by	
  the	
  
   end	
  of	
  2014	
  
HTML5	
  vs	
  XHTML5	
  
•  XHTML5	
  is	
  XML	
  serializaCon	
  of	
  HTML5	
  
    –  internet	
  media	
  type:	
  applica&on/xhtml+xml	
  or	
  applica&on/
       xml	
  
    –  <!DOCTYPE	
  html>	
  
•  HTML5	
  
    –  <!DOCTYPE	
  html>	
  opConal	
  
•  HTML5	
  uses	
  polyglot	
  markup	
  
    –  valid	
  HTML	
  document	
  and	
  well-­‐formed	
  XML	
  document	
  
    –  Certain	
  elements	
  are	
  wriFen	
  using	
  minimized	
  tag	
  <br/>	
  
    –  And	
  certain	
  not:	
  <p></p>	
  
    –  hFp://dev.w3.org/html5/html-­‐xhtml-­‐author-­‐guide/html-­‐
       xhtml-­‐authoring-­‐guide.html#empty-­‐elements	
  
Minimal	
  HTML5	
  document	
  
<!-- XML declaration is required -->
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>
    </title>
    <!-- UTF-8 is recommended -->
    <meta charset="UTF-8" />
  </head>

  <body>
    <svg xmlns="http://www.w3.org/2000/svg">
      <rect stroke="black" fill="blue" x="45px" y="45px" width="200px"
height="100px" stroke-width="2" />
    </svg>
  </body>
</html>
What	
  is	
  New?	
  
•  New	
  elements,	
  aFributes	
  
    –  SemanCc	
  elements,	
  HTML5	
  Forms	
  
•  Video	
  and	
  audio	
  
    –  Lot	
  easier	
  to	
  show	
  <video>	
  and	
  <audio>	
  
•  2D/3D	
  Graphics	
  
    –  <canvas>	
  -­‐	
  element,	
  inline	
  SVG,	
  CSS	
  2D/3D	
  
•  New	
  APIs	
  
    –  Data	
  storage,	
  SQL	
  Database,	
  JS	
  workers	
  
Video	
  
<video width="320" height="240" controls="controls">
   <source src="scroll_indicator.mp4" type="video/mp4">
   <source src="scroll_indicator.ogg" type="video/ogg">
   Your browser does not support the video tag.
 </video>
SemanCc	
  Elements	
  
•  Before	
  
   –  <div	
  id="header">..</div>	
  
•  Now	
  
   –  <secCon>,	
  <arCcle>,	
  <header>,	
  <nav>	
  
Exercise	
  
•  Implement	
  HTML5	
  document	
  and	
  use	
  the	
  new	
  
   features:	
  
    –  header,	
  footer,	
  video,	
  arCcle,	
  secCon,	
  hgroup,	
  
       aside,	
  figure,	
  figcapCon,	
  Cme,	
  mark,	
  wbr,	
  	
  
•  See:	
  
    –  hFp://www.html-­‐5-­‐tutorial.com/	
  
APIs	
  
•  APIs	
  and	
  DOM	
  is	
  fundamental	
  part	
  of	
  the	
  
   specificaCon	
  
•  APIs	
  
    –  Offline	
  Web	
  apps	
  
    –  Drag	
  and	
  drop	
  
    –  GeolocaCon	
  
    –  Web	
  SQL	
  database	
  
    –  …	
  
GeolocaCon	
  API	
  
•  GeolocaCon	
  API	
  SpecificaCon	
  
    –  hFp://dev.w3.org/geo/api/spec-­‐source.html	
  
•  To	
  detect	
  the	
  locaCon	
  of	
  the	
  client	
  
•  In	
  mobile:	
  GPS,	
  in	
  desktop	
  IP-­‐address	
  or	
  Wi-­‐Fi	
  
   locaCon	
  
Browser	
  Support	
  
•    IE9	
  
•    Firefox	
  3.5	
  
•    Chrome	
  5	
  
•    Opera	
  10.6	
  
•    Safari	
  5	
  
•    iPhone	
  3	
  
•    Android	
  2	
  
•    WP	
  7.5	
  
function setText(val, e) {
    document.getElementById(e).value = val;
}

function insertText(val, e) {
    document.getElementById(e).value += val;
}

var nav = null;

function requestPosition() {
  if (nav == null) {
      nav = window.navigator;
  }
  if (nav != null) {
      var geoloc = nav.geolocation;
      if (geoloc != null) {
          geoloc.getCurrentPosition(successCallback);
      }
      else {
          alert("geolocation not supported");
      }
  }
  else {
      alert("Navigator not found");
  }
}

function successCallback(position)
{
   alert("" + position.coords.latitude + ", " + position.coords.longitude);
}
Showing	
  Map	
  on	
  Google	
  API	
  
•  hFp://maps.googleapis.com/maps/api/
   staCcmap?
   center=<laCtude>,<longitude>&zoom=10&siz
   e=200x200&maptype=roadmap	
  

•  See:	
  	
  
     –  hFps://developers.google.com/maps/
        documentaCon/staCcmaps/	
  
Wunderground	
  +	
  GeolocaCon	
  +	
  
           Google	
  staCc	
  map	
  
•  Wunderground	
  provides	
  JSON	
  API	
  for	
  weather	
  
   informaCon	
  
•  Get	
  locaCon	
  of	
  the	
  browser	
  and	
  AJAX	
  request	
  
   to	
  wunderground	
  
•  Aqer	
  receiving	
  the	
  result,	
  parse	
  it	
  and	
  show	
  
   results	
  in	
  html.	
  
•  Problem:	
  AJAX	
  does	
  not	
  work	
  cross	
  site..	
  You	
  
   can	
  implement	
  middleware	
  (PHP)	
  
Mobile	
  App	
  (iPhone)	
  



                          Web	
  app!	
  
Mobile	
  App	
  (iPhone)	
  
Canvas	
  
•  “The	
  canvas	
  element	
  a	
  resolu&on-­‐dependent	
  
   bitmap	
  canvas,	
  which	
  can	
  be	
  used	
  for	
  
   dynamically	
  rendering	
  of	
  images	
  such	
  as	
  game	
  
   graphics,	
  graphs,	
  or	
  other	
  images”	
  
•  Image	
  is	
  drawn	
  in	
  JavaScript	
  using	
  typical	
  vector	
  
   graphics	
  drawing	
  primiCves	
  
    –  drawImage(),	
  lineTo(),	
  arcTo(),	
  bezierCurveTo(),	
  
       fillRect(),	
  scale(),	
  rotate(),	
  translate(),	
  
       createLinearGradient(),	
  shadowBlur(),	
  …	
  
       	
  
Simple	
  Drawing	
  using	
  Canvas	
  and	
  JS	
  
<canvas id="mycanvas" width="200" height="200">
</canvas>
<script>
var canvas= document.getElementById('mycanvas');
var context = canvas.getContext('2d');
context.fillRect(60,30,80,120);
</script>
PossibiliCes	
  
•      Simple	
  shapes	
  (Rectangles)	
  
•      Complex	
  shapes	
  (Paths)	
  	
  
•      Lines	
  
•      Shadows	
  
•      Text	
  
•      Images	
  
•      Pixel	
  manipulaCon	
  
•      Colors	
  and	
  styles	
  
•      ComposiCng	
  
•      TransformaCons	
  
•      Canvas	
  state	
  
	
  
ImplemenCng	
  a	
  Game	
  
main	
  
function main() {
    createCanvas();

    // Original position
    reset();

    // Millisecs elapsed since 1970.
    then = Date.now();

    loadImages();

    setEventListeners();

    //The setInterval() method calls a function or evaluates an expression at
    //specified intervals (in milliseconds).
    setInterval(gameLoop, 1);
}

window.onload=function(){
    main();
}
Game	
  Objects	
  and	
  Global	
  Variables	
  
var   keysDown = {};
var   bgImage = null;
var   canvas = null;
var   ctx     = null;
var   then;
var   monstersCaught = 0;

// Game objects
var hero = {
     speed: 256,
     x: 0,
     y: 0,
     myImage: null
};

var monster = {
     x: 0,
     y: 0,
     myImage: null
};
Game	
  Loop	
  
function gameLoop () {
    var now = Date.now();
    var delta = now - then;

     update(delta / 1000);
     render();

     then = now;
};
Create	
  Canvas	
  
function createCanvas() {
    // Create canvas element
    canvas = document.createElement("canvas");

    // Get the canvas object that you can use to draw
    ctx = canvas.getContext("2d");

    // Set size for the canvas object
    canvas.width = 512;
    canvas.height = 480;

    document.getElementById("here").appendChild(canvas);
}
StarCng	
  point	
  
function reset() {
    hero.x = canvas.width / 2;
    hero.y = canvas.height / 2;

     // Throw the monster somewhere on the screen randomly
     monster.x = 32 + (Math.random() * (canvas.width - 64));
     monster.y = 32 + (Math.random() * (canvas.height - 64));
};
Load	
  Image	
  
function loadImage(imageSrc) {
    var image = new Image();
    image.src = imageSrc;
    return image;
}
function loadImages() {
    hero.myImage    = loadImage("lib/hero.png");
    monster.myImage = loadImage("lib/monster.png");
    bgImage         = loadImage("lib/background.jpg");
}
Key	
  Listeners	
  
function setEventListeners() {
    // If keydown, then add the key to the array and set it true
    addEventListener("keydown", function (e) {
        keysDown[e.keyCode] = true;
    }, false);

    // If keyup, remove it from the array
    addEventListener("keyup", function (e) {
        delete keysDown[e.keyCode];
    }, false);
}
Update	
  
function update (modifier) {
     if (38 in keysDown) { // Player holding   up
          hero.y -= hero.speed * modifier;
     }
     if (40 in keysDown) { // Player holding   down
          hero.y += hero.speed * modifier;
     }
     if (37 in keysDown) { // Player holding   left
          hero.x -= hero.speed * modifier;
     }
     if (39 in keysDown) { // Player holding   right
          hero.x += hero.speed * modifier;
     }

     // Are they touching?
     if (
          hero.x <= (monster.x + 32)
          && monster.x <= (hero.x + 32)
          && hero.y <= (monster.y + 32)
          && monster.y <= (hero.y + 32)
     ) {
          ++monstersCaught;
          reset();
     }
};
Render	
  
function render() {
    ctx.drawImage(bgImage, 0, 0);
    ctx.drawImage(hero.myImage, hero.x, hero.y);
    ctx.drawImage(monster.myImage, monster.x, monster.y);

     // Score
     ctx.fillStyle = "rgb(250, 250, 250)";
     ctx.font = "12px Helvetica";
     ctx.textAlign = "left";
     ctx.textBaseline = "top";
     ctx.fillText("FB Monsters caught: " + monstersCaught, 20, 20);
};

Más contenido relacionado

La actualidad más candente

jQuery (BostonPHP)
jQuery (BostonPHP)jQuery (BostonPHP)
jQuery (BostonPHP)jeresig
 
Browsers with Wings
Browsers with WingsBrowsers with Wings
Browsers with WingsRemy Sharp
 
Vue.js + Django - configuración para desarrollo con webpack y HMR
Vue.js + Django - configuración para desarrollo con webpack y HMRVue.js + Django - configuración para desarrollo con webpack y HMR
Vue.js + Django - configuración para desarrollo con webpack y HMRJavier Abadía
 
JavaScript & HTML5 - Brave New World
JavaScript & HTML5 - Brave New WorldJavaScript & HTML5 - Brave New World
JavaScript & HTML5 - Brave New WorldRobert Nyman
 
IndexedDB - Querying and Performance
IndexedDB - Querying and PerformanceIndexedDB - Querying and Performance
IndexedDB - Querying and PerformanceParashuram N
 
HTML5 JavaScript APIs
HTML5 JavaScript APIsHTML5 JavaScript APIs
HTML5 JavaScript APIsRemy Sharp
 
jQuery (MeshU)
jQuery (MeshU)jQuery (MeshU)
jQuery (MeshU)jeresig
 
jQuery (DrupalCamp Toronto)
jQuery (DrupalCamp Toronto)jQuery (DrupalCamp Toronto)
jQuery (DrupalCamp Toronto)jeresig
 
kissy-past-now-future
kissy-past-now-futurekissy-past-now-future
kissy-past-now-futureyiming he
 
KISSY 的昨天、今天与明天
KISSY 的昨天、今天与明天KISSY 的昨天、今天与明天
KISSY 的昨天、今天与明天tblanlan
 
HTML5 Canvas - The Future of Graphics on the Web
HTML5 Canvas - The Future of Graphics on the WebHTML5 Canvas - The Future of Graphics on the Web
HTML5 Canvas - The Future of Graphics on the WebRobin Hawkes
 
Jarv.us Showcase — SenchaCon 2011
Jarv.us Showcase — SenchaCon 2011Jarv.us Showcase — SenchaCon 2011
Jarv.us Showcase — SenchaCon 2011Chris Alfano
 
codebits 2009 HTML5 JS APIs
codebits 2009 HTML5 JS APIscodebits 2009 HTML5 JS APIs
codebits 2009 HTML5 JS APIsRemy Sharp
 
HTML5: friend or foe (to Flash)?
HTML5: friend or foe (to Flash)?HTML5: friend or foe (to Flash)?
HTML5: friend or foe (to Flash)?Remy Sharp
 
Reactive Type-safe WebComponents
Reactive Type-safe WebComponentsReactive Type-safe WebComponents
Reactive Type-safe WebComponentsMartin Hochel
 
Introducing Assetic: Asset Management for PHP 5.3
Introducing Assetic: Asset Management for PHP 5.3Introducing Assetic: Asset Management for PHP 5.3
Introducing Assetic: Asset Management for PHP 5.3Kris Wallsmith
 
Developing for Plone using ArchGenXML / ArgoUML
Developing for Plone using ArchGenXML / ArgoUMLDeveloping for Plone using ArchGenXML / ArgoUML
Developing for Plone using ArchGenXML / ArgoUMLJazkarta, Inc.
 
前端MVC 豆瓣说
前端MVC 豆瓣说前端MVC 豆瓣说
前端MVC 豆瓣说Ting Lv
 

La actualidad más candente (20)

jQuery (BostonPHP)
jQuery (BostonPHP)jQuery (BostonPHP)
jQuery (BostonPHP)
 
Progressive What Apps?
Progressive What Apps?Progressive What Apps?
Progressive What Apps?
 
Browsers with Wings
Browsers with WingsBrowsers with Wings
Browsers with Wings
 
Vue.js + Django - configuración para desarrollo con webpack y HMR
Vue.js + Django - configuración para desarrollo con webpack y HMRVue.js + Django - configuración para desarrollo con webpack y HMR
Vue.js + Django - configuración para desarrollo con webpack y HMR
 
JavaScript & HTML5 - Brave New World
JavaScript & HTML5 - Brave New WorldJavaScript & HTML5 - Brave New World
JavaScript & HTML5 - Brave New World
 
IndexedDB - Querying and Performance
IndexedDB - Querying and PerformanceIndexedDB - Querying and Performance
IndexedDB - Querying and Performance
 
HTML5 JavaScript APIs
HTML5 JavaScript APIsHTML5 JavaScript APIs
HTML5 JavaScript APIs
 
jQuery (MeshU)
jQuery (MeshU)jQuery (MeshU)
jQuery (MeshU)
 
jQuery (DrupalCamp Toronto)
jQuery (DrupalCamp Toronto)jQuery (DrupalCamp Toronto)
jQuery (DrupalCamp Toronto)
 
kissy-past-now-future
kissy-past-now-futurekissy-past-now-future
kissy-past-now-future
 
KISSY 的昨天、今天与明天
KISSY 的昨天、今天与明天KISSY 的昨天、今天与明天
KISSY 的昨天、今天与明天
 
HTML5 Canvas - The Future of Graphics on the Web
HTML5 Canvas - The Future of Graphics on the WebHTML5 Canvas - The Future of Graphics on the Web
HTML5 Canvas - The Future of Graphics on the Web
 
Jarv.us Showcase — SenchaCon 2011
Jarv.us Showcase — SenchaCon 2011Jarv.us Showcase — SenchaCon 2011
Jarv.us Showcase — SenchaCon 2011
 
codebits 2009 HTML5 JS APIs
codebits 2009 HTML5 JS APIscodebits 2009 HTML5 JS APIs
codebits 2009 HTML5 JS APIs
 
YouDrup_in_Drupal
YouDrup_in_DrupalYouDrup_in_Drupal
YouDrup_in_Drupal
 
HTML5: friend or foe (to Flash)?
HTML5: friend or foe (to Flash)?HTML5: friend or foe (to Flash)?
HTML5: friend or foe (to Flash)?
 
Reactive Type-safe WebComponents
Reactive Type-safe WebComponentsReactive Type-safe WebComponents
Reactive Type-safe WebComponents
 
Introducing Assetic: Asset Management for PHP 5.3
Introducing Assetic: Asset Management for PHP 5.3Introducing Assetic: Asset Management for PHP 5.3
Introducing Assetic: Asset Management for PHP 5.3
 
Developing for Plone using ArchGenXML / ArgoUML
Developing for Plone using ArchGenXML / ArgoUMLDeveloping for Plone using ArchGenXML / ArgoUML
Developing for Plone using ArchGenXML / ArgoUML
 
前端MVC 豆瓣说
前端MVC 豆瓣说前端MVC 豆瓣说
前端MVC 豆瓣说
 

Destacado

An Intro to HTML5 and CSS3
An Intro to HTML5 and CSS3An Intro to HTML5 and CSS3
An Intro to HTML5 and CSS3Dhruva Krishnan
 
An Seo’s Intro to Web Dev, HTML, CSS and JavaScript
An Seo’s Intro to Web Dev, HTML, CSS and JavaScriptAn Seo’s Intro to Web Dev, HTML, CSS and JavaScript
An Seo’s Intro to Web Dev, HTML, CSS and JavaScriptTroyfawkes
 
Web Server - Internet Applications
Web Server - Internet ApplicationsWeb Server - Internet Applications
Web Server - Internet Applicationssandra sukarieh
 
Internet, domain name, worldwideweb
Internet, domain name, worldwidewebInternet, domain name, worldwideweb
Internet, domain name, worldwidewebSaurabh Pandey
 
Introduction of Html/css/js
Introduction of Html/css/jsIntroduction of Html/css/js
Introduction of Html/css/jsKnoldus Inc.
 
Conferencia HTML5 y CSS3 por Alexandra García Milan
Conferencia HTML5 y CSS3 por Alexandra García MilanConferencia HTML5 y CSS3 por Alexandra García Milan
Conferencia HTML5 y CSS3 por Alexandra García MilanAndres Karp
 
Computer networks
Computer networksComputer networks
Computer networksTej Kiran
 
Web Front End - (HTML5, CSS3, JavaScript) ++
Web Front End - (HTML5, CSS3, JavaScript) ++Web Front End - (HTML5, CSS3, JavaScript) ++
Web Front End - (HTML5, CSS3, JavaScript) ++ubshreenath
 
Untangling spring week5
Untangling spring week5Untangling spring week5
Untangling spring week5Derek Jacoby
 
An Introduction To HTML5
An Introduction To HTML5An Introduction To HTML5
An Introduction To HTML5Robert Nyman
 
Internet of Things
Internet of ThingsInternet of Things
Internet of ThingsVala Afshar
 

Destacado (17)

An Intro to HTML5 and CSS3
An Intro to HTML5 and CSS3An Intro to HTML5 and CSS3
An Intro to HTML5 and CSS3
 
Responsive Web Design
Responsive Web DesignResponsive Web Design
Responsive Web Design
 
An Seo’s Intro to Web Dev, HTML, CSS and JavaScript
An Seo’s Intro to Web Dev, HTML, CSS and JavaScriptAn Seo’s Intro to Web Dev, HTML, CSS and JavaScript
An Seo’s Intro to Web Dev, HTML, CSS and JavaScript
 
Web Server - Internet Applications
Web Server - Internet ApplicationsWeb Server - Internet Applications
Web Server - Internet Applications
 
Internet, domain name, worldwideweb
Internet, domain name, worldwidewebInternet, domain name, worldwideweb
Internet, domain name, worldwideweb
 
Introduction of Html/css/js
Introduction of Html/css/jsIntroduction of Html/css/js
Introduction of Html/css/js
 
Conferencia HTML5 y CSS3 por Alexandra García Milan
Conferencia HTML5 y CSS3 por Alexandra García MilanConferencia HTML5 y CSS3 por Alexandra García Milan
Conferencia HTML5 y CSS3 por Alexandra García Milan
 
Computer networks
Computer networksComputer networks
Computer networks
 
Web Front End - (HTML5, CSS3, JavaScript) ++
Web Front End - (HTML5, CSS3, JavaScript) ++Web Front End - (HTML5, CSS3, JavaScript) ++
Web Front End - (HTML5, CSS3, JavaScript) ++
 
Photo and photo
Photo and photoPhoto and photo
Photo and photo
 
HTML CSS & Javascript
HTML CSS & JavascriptHTML CSS & Javascript
HTML CSS & Javascript
 
Untangling spring week5
Untangling spring week5Untangling spring week5
Untangling spring week5
 
Introduction to HTML5 & CSS3
Introduction to HTML5 & CSS3Introduction to HTML5 & CSS3
Introduction to HTML5 & CSS3
 
An Introduction To HTML5
An Introduction To HTML5An Introduction To HTML5
An Introduction To HTML5
 
Web Servers (ppt)
Web Servers (ppt)Web Servers (ppt)
Web Servers (ppt)
 
Html JavaScript and CSS
Html JavaScript and CSSHtml JavaScript and CSS
Html JavaScript and CSS
 
Internet of Things
Internet of ThingsInternet of Things
Internet of Things
 

Similar a Intro to HTML5

Webgl para JavaScripters
Webgl para JavaScriptersWebgl para JavaScripters
Webgl para JavaScriptersgerbille
 
Is html5-ready-workshop-110727181512-phpapp02
Is html5-ready-workshop-110727181512-phpapp02Is html5-ready-workshop-110727181512-phpapp02
Is html5-ready-workshop-110727181512-phpapp02PL dream
 
New Elements & Features in HTML5
New Elements & Features in HTML5New Elements & Features in HTML5
New Elements & Features in HTML5Jamshid Hashimi
 
HTML5 (and friends) - History, overview and current status - jsDay Verona 11....
HTML5 (and friends) - History, overview and current status - jsDay Verona 11....HTML5 (and friends) - History, overview and current status - jsDay Verona 11....
HTML5 (and friends) - History, overview and current status - jsDay Verona 11....Patrick Lauke
 
Firefox OS, une plateforme à découvrir - IO Saglac - 2014-09-09
Firefox OS, une plateforme à découvrir - IO Saglac - 2014-09-09Firefox OS, une plateforme à découvrir - IO Saglac - 2014-09-09
Firefox OS, une plateforme à découvrir - IO Saglac - 2014-09-09Frédéric Harper
 
Web Performance Part 4 "Client-side performance"
Web Performance Part 4  "Client-side performance"Web Performance Part 4  "Client-side performance"
Web Performance Part 4 "Client-side performance"Binary Studio
 
JavaScript para Graficos y Visualizacion de Datos
JavaScript para Graficos y Visualizacion de DatosJavaScript para Graficos y Visualizacion de Datos
JavaScript para Graficos y Visualizacion de Datosphilogb
 
HTML5 - Daha Flash bir web?
HTML5 - Daha Flash bir web?HTML5 - Daha Flash bir web?
HTML5 - Daha Flash bir web?Ankara JUG
 
[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVCAlive Kuo
 
The Future of CSS with Web components
The Future of CSS with Web componentsThe Future of CSS with Web components
The Future of CSS with Web componentsdevObjective
 
The Future of CSS with Web Components
The Future of CSS with Web ComponentsThe Future of CSS with Web Components
The Future of CSS with Web ComponentsColdFusionConference
 
JavaScript para Graficos y Visualizacion de Datos - BogotaJS
JavaScript para Graficos y Visualizacion de Datos - BogotaJSJavaScript para Graficos y Visualizacion de Datos - BogotaJS
JavaScript para Graficos y Visualizacion de Datos - BogotaJSphilogb
 
Primefaces Nextgen Lju
Primefaces Nextgen LjuPrimefaces Nextgen Lju
Primefaces Nextgen LjuSkills Matter
 

Similar a Intro to HTML5 (20)

Webgl para JavaScripters
Webgl para JavaScriptersWebgl para JavaScripters
Webgl para JavaScripters
 
Is html5-ready-workshop-110727181512-phpapp02
Is html5-ready-workshop-110727181512-phpapp02Is html5-ready-workshop-110727181512-phpapp02
Is html5-ready-workshop-110727181512-phpapp02
 
New Elements & Features in HTML5
New Elements & Features in HTML5New Elements & Features in HTML5
New Elements & Features in HTML5
 
HTML5 (and friends) - History, overview and current status - jsDay Verona 11....
HTML5 (and friends) - History, overview and current status - jsDay Verona 11....HTML5 (and friends) - History, overview and current status - jsDay Verona 11....
HTML5 (and friends) - History, overview and current status - jsDay Verona 11....
 
WebXR if X = how?
WebXR if X = how?WebXR if X = how?
WebXR if X = how?
 
Firefox OS, une plateforme à découvrir - IO Saglac - 2014-09-09
Firefox OS, une plateforme à découvrir - IO Saglac - 2014-09-09Firefox OS, une plateforme à découvrir - IO Saglac - 2014-09-09
Firefox OS, une plateforme à découvrir - IO Saglac - 2014-09-09
 
Html5 For Jjugccc2009fall
Html5 For Jjugccc2009fallHtml5 For Jjugccc2009fall
Html5 For Jjugccc2009fall
 
Html5
Html5Html5
Html5
 
Web Performance Part 4 "Client-side performance"
Web Performance Part 4  "Client-side performance"Web Performance Part 4  "Client-side performance"
Web Performance Part 4 "Client-side performance"
 
JavaScript para Graficos y Visualizacion de Datos
JavaScript para Graficos y Visualizacion de DatosJavaScript para Graficos y Visualizacion de Datos
JavaScript para Graficos y Visualizacion de Datos
 
HTML5 - Daha Flash bir web?
HTML5 - Daha Flash bir web?HTML5 - Daha Flash bir web?
HTML5 - Daha Flash bir web?
 
mobl
moblmobl
mobl
 
A More Flash Like Web?
A More Flash Like Web?A More Flash Like Web?
A More Flash Like Web?
 
[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC
 
The Future of CSS with Web components
The Future of CSS with Web componentsThe Future of CSS with Web components
The Future of CSS with Web components
 
The Future of CSS with Web Components
The Future of CSS with Web ComponentsThe Future of CSS with Web Components
The Future of CSS with Web Components
 
JavaScript para Graficos y Visualizacion de Datos - BogotaJS
JavaScript para Graficos y Visualizacion de Datos - BogotaJSJavaScript para Graficos y Visualizacion de Datos - BogotaJS
JavaScript para Graficos y Visualizacion de Datos - BogotaJS
 
HTML 5 - Overview
HTML 5 - OverviewHTML 5 - Overview
HTML 5 - Overview
 
Phone Gap
Phone GapPhone Gap
Phone Gap
 
Primefaces Nextgen Lju
Primefaces Nextgen LjuPrimefaces Nextgen Lju
Primefaces Nextgen Lju
 

Más de Jussi Pohjolainen

libGDX: Screens, Fonts and Preferences
libGDX: Screens, Fonts and PreferenceslibGDX: Screens, Fonts and Preferences
libGDX: Screens, Fonts and PreferencesJussi Pohjolainen
 
libGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame AnimationlibGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame AnimationJussi Pohjolainen
 
Intro to Building Android Games using libGDX
Intro to Building Android Games using libGDXIntro to Building Android Games using libGDX
Intro to Building Android Games using libGDXJussi Pohjolainen
 
Advanced JavaScript Development
Advanced JavaScript DevelopmentAdvanced JavaScript Development
Advanced JavaScript DevelopmentJussi Pohjolainen
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame AnimationJussi Pohjolainen
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame AnimationJussi Pohjolainen
 
Implementing a Simple Game using libGDX
Implementing a Simple Game using libGDXImplementing a Simple Game using libGDX
Implementing a Simple Game using libGDXJussi Pohjolainen
 
Building Android games using LibGDX
Building Android games using LibGDXBuilding Android games using LibGDX
Building Android games using LibGDXJussi Pohjolainen
 
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and GesturesCreating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and GesturesJussi Pohjolainen
 
Creating Games for Asha - platform
Creating Games for Asha - platformCreating Games for Asha - platform
Creating Games for Asha - platformJussi Pohjolainen
 

Más de Jussi Pohjolainen (20)

Moved to Speakerdeck
Moved to SpeakerdeckMoved to Speakerdeck
Moved to Speakerdeck
 
Java Web Services
Java Web ServicesJava Web Services
Java Web Services
 
Box2D and libGDX
Box2D and libGDXBox2D and libGDX
Box2D and libGDX
 
libGDX: Screens, Fonts and Preferences
libGDX: Screens, Fonts and PreferenceslibGDX: Screens, Fonts and Preferences
libGDX: Screens, Fonts and Preferences
 
libGDX: Tiled Maps
libGDX: Tiled MapslibGDX: Tiled Maps
libGDX: Tiled Maps
 
libGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame AnimationlibGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame Animation
 
Intro to Building Android Games using libGDX
Intro to Building Android Games using libGDXIntro to Building Android Games using libGDX
Intro to Building Android Games using libGDX
 
Advanced JavaScript Development
Advanced JavaScript DevelopmentAdvanced JavaScript Development
Advanced JavaScript Development
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
 
libGDX: Scene2D
libGDX: Scene2DlibGDX: Scene2D
libGDX: Scene2D
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame Animation
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame Animation
 
libGDX: User Input
libGDX: User InputlibGDX: User Input
libGDX: User Input
 
Implementing a Simple Game using libGDX
Implementing a Simple Game using libGDXImplementing a Simple Game using libGDX
Implementing a Simple Game using libGDX
 
Building Android games using LibGDX
Building Android games using LibGDXBuilding Android games using LibGDX
Building Android games using LibGDX
 
Android Threading
Android ThreadingAndroid Threading
Android Threading
 
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and GesturesCreating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
 
Creating Games for Asha - platform
Creating Games for Asha - platformCreating Games for Asha - platform
Creating Games for Asha - platform
 
Intro to Asha UI
Intro to Asha UIIntro to Asha UI
Intro to Asha UI
 

Último

Future Of Sample Report 2024 | Redacted Version
Future Of Sample Report 2024 | Redacted VersionFuture Of Sample Report 2024 | Redacted Version
Future Of Sample Report 2024 | Redacted VersionMintel Group
 
Annual General Meeting Presentation Slides
Annual General Meeting Presentation SlidesAnnual General Meeting Presentation Slides
Annual General Meeting Presentation SlidesKeppelCorporation
 
Islamabad Escorts | Call 03070433345 | Escort Service in Islamabad
Islamabad Escorts | Call 03070433345 | Escort Service in IslamabadIslamabad Escorts | Call 03070433345 | Escort Service in Islamabad
Islamabad Escorts | Call 03070433345 | Escort Service in IslamabadAyesha Khan
 
Intro to BCG's Carbon Emissions Benchmark_vF.pdf
Intro to BCG's Carbon Emissions Benchmark_vF.pdfIntro to BCG's Carbon Emissions Benchmark_vF.pdf
Intro to BCG's Carbon Emissions Benchmark_vF.pdfpollardmorgan
 
Call US-88OO1O2216 Call Girls In Mahipalpur Female Escort Service
Call US-88OO1O2216 Call Girls In Mahipalpur Female Escort ServiceCall US-88OO1O2216 Call Girls In Mahipalpur Female Escort Service
Call US-88OO1O2216 Call Girls In Mahipalpur Female Escort Servicecallgirls2057
 
Flow Your Strategy at Flight Levels Day 2024
Flow Your Strategy at Flight Levels Day 2024Flow Your Strategy at Flight Levels Day 2024
Flow Your Strategy at Flight Levels Day 2024Kirill Klimov
 
Call Us 📲8800102216📞 Call Girls In DLF City Gurgaon
Call Us 📲8800102216📞 Call Girls In DLF City GurgaonCall Us 📲8800102216📞 Call Girls In DLF City Gurgaon
Call Us 📲8800102216📞 Call Girls In DLF City Gurgaoncallgirls2057
 
Ms Motilal Padampat Sugar Mills vs. State of Uttar Pradesh & Ors. - A Milesto...
Ms Motilal Padampat Sugar Mills vs. State of Uttar Pradesh & Ors. - A Milesto...Ms Motilal Padampat Sugar Mills vs. State of Uttar Pradesh & Ors. - A Milesto...
Ms Motilal Padampat Sugar Mills vs. State of Uttar Pradesh & Ors. - A Milesto...ShrutiBose4
 
Case study on tata clothing brand zudio in detail
Case study on tata clothing brand zudio in detailCase study on tata clothing brand zudio in detail
Case study on tata clothing brand zudio in detailAriel592675
 
8447779800, Low rate Call girls in New Ashok Nagar Delhi NCR
8447779800, Low rate Call girls in New Ashok Nagar Delhi NCR8447779800, Low rate Call girls in New Ashok Nagar Delhi NCR
8447779800, Low rate Call girls in New Ashok Nagar Delhi NCRashishs7044
 
NewBase 19 April 2024 Energy News issue - 1717 by Khaled Al Awadi.pdf
NewBase  19 April  2024  Energy News issue - 1717 by Khaled Al Awadi.pdfNewBase  19 April  2024  Energy News issue - 1717 by Khaled Al Awadi.pdf
NewBase 19 April 2024 Energy News issue - 1717 by Khaled Al Awadi.pdfKhaled Al Awadi
 
MAHA Global and IPR: Do Actions Speak Louder Than Words?
MAHA Global and IPR: Do Actions Speak Louder Than Words?MAHA Global and IPR: Do Actions Speak Louder Than Words?
MAHA Global and IPR: Do Actions Speak Louder Than Words?Olivia Kresic
 
Organizational Structure Running A Successful Business
Organizational Structure Running A Successful BusinessOrganizational Structure Running A Successful Business
Organizational Structure Running A Successful BusinessSeta Wicaksana
 
8447779800, Low rate Call girls in Uttam Nagar Delhi NCR
8447779800, Low rate Call girls in Uttam Nagar Delhi NCR8447779800, Low rate Call girls in Uttam Nagar Delhi NCR
8447779800, Low rate Call girls in Uttam Nagar Delhi NCRashishs7044
 
Buy gmail accounts.pdf Buy Old Gmail Accounts
Buy gmail accounts.pdf Buy Old Gmail AccountsBuy gmail accounts.pdf Buy Old Gmail Accounts
Buy gmail accounts.pdf Buy Old Gmail AccountsBuy Verified Accounts
 
Traction part 2 - EOS Model JAX Bridges.
Traction part 2 - EOS Model JAX Bridges.Traction part 2 - EOS Model JAX Bridges.
Traction part 2 - EOS Model JAX Bridges.Anamaria Contreras
 
PSCC - Capability Statement Presentation
PSCC - Capability Statement PresentationPSCC - Capability Statement Presentation
PSCC - Capability Statement PresentationAnamaria Contreras
 
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu Menza
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu MenzaYouth Involvement in an Innovative Coconut Value Chain by Mwalimu Menza
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu Menzaictsugar
 

Último (20)

Future Of Sample Report 2024 | Redacted Version
Future Of Sample Report 2024 | Redacted VersionFuture Of Sample Report 2024 | Redacted Version
Future Of Sample Report 2024 | Redacted Version
 
Annual General Meeting Presentation Slides
Annual General Meeting Presentation SlidesAnnual General Meeting Presentation Slides
Annual General Meeting Presentation Slides
 
Islamabad Escorts | Call 03070433345 | Escort Service in Islamabad
Islamabad Escorts | Call 03070433345 | Escort Service in IslamabadIslamabad Escorts | Call 03070433345 | Escort Service in Islamabad
Islamabad Escorts | Call 03070433345 | Escort Service in Islamabad
 
Intro to BCG's Carbon Emissions Benchmark_vF.pdf
Intro to BCG's Carbon Emissions Benchmark_vF.pdfIntro to BCG's Carbon Emissions Benchmark_vF.pdf
Intro to BCG's Carbon Emissions Benchmark_vF.pdf
 
Call US-88OO1O2216 Call Girls In Mahipalpur Female Escort Service
Call US-88OO1O2216 Call Girls In Mahipalpur Female Escort ServiceCall US-88OO1O2216 Call Girls In Mahipalpur Female Escort Service
Call US-88OO1O2216 Call Girls In Mahipalpur Female Escort Service
 
Flow Your Strategy at Flight Levels Day 2024
Flow Your Strategy at Flight Levels Day 2024Flow Your Strategy at Flight Levels Day 2024
Flow Your Strategy at Flight Levels Day 2024
 
Call Us 📲8800102216📞 Call Girls In DLF City Gurgaon
Call Us 📲8800102216📞 Call Girls In DLF City GurgaonCall Us 📲8800102216📞 Call Girls In DLF City Gurgaon
Call Us 📲8800102216📞 Call Girls In DLF City Gurgaon
 
Corporate Profile 47Billion Information Technology
Corporate Profile 47Billion Information TechnologyCorporate Profile 47Billion Information Technology
Corporate Profile 47Billion Information Technology
 
Ms Motilal Padampat Sugar Mills vs. State of Uttar Pradesh & Ors. - A Milesto...
Ms Motilal Padampat Sugar Mills vs. State of Uttar Pradesh & Ors. - A Milesto...Ms Motilal Padampat Sugar Mills vs. State of Uttar Pradesh & Ors. - A Milesto...
Ms Motilal Padampat Sugar Mills vs. State of Uttar Pradesh & Ors. - A Milesto...
 
Case study on tata clothing brand zudio in detail
Case study on tata clothing brand zudio in detailCase study on tata clothing brand zudio in detail
Case study on tata clothing brand zudio in detail
 
Call Us ➥9319373153▻Call Girls In North Goa
Call Us ➥9319373153▻Call Girls In North GoaCall Us ➥9319373153▻Call Girls In North Goa
Call Us ➥9319373153▻Call Girls In North Goa
 
8447779800, Low rate Call girls in New Ashok Nagar Delhi NCR
8447779800, Low rate Call girls in New Ashok Nagar Delhi NCR8447779800, Low rate Call girls in New Ashok Nagar Delhi NCR
8447779800, Low rate Call girls in New Ashok Nagar Delhi NCR
 
NewBase 19 April 2024 Energy News issue - 1717 by Khaled Al Awadi.pdf
NewBase  19 April  2024  Energy News issue - 1717 by Khaled Al Awadi.pdfNewBase  19 April  2024  Energy News issue - 1717 by Khaled Al Awadi.pdf
NewBase 19 April 2024 Energy News issue - 1717 by Khaled Al Awadi.pdf
 
MAHA Global and IPR: Do Actions Speak Louder Than Words?
MAHA Global and IPR: Do Actions Speak Louder Than Words?MAHA Global and IPR: Do Actions Speak Louder Than Words?
MAHA Global and IPR: Do Actions Speak Louder Than Words?
 
Organizational Structure Running A Successful Business
Organizational Structure Running A Successful BusinessOrganizational Structure Running A Successful Business
Organizational Structure Running A Successful Business
 
8447779800, Low rate Call girls in Uttam Nagar Delhi NCR
8447779800, Low rate Call girls in Uttam Nagar Delhi NCR8447779800, Low rate Call girls in Uttam Nagar Delhi NCR
8447779800, Low rate Call girls in Uttam Nagar Delhi NCR
 
Buy gmail accounts.pdf Buy Old Gmail Accounts
Buy gmail accounts.pdf Buy Old Gmail AccountsBuy gmail accounts.pdf Buy Old Gmail Accounts
Buy gmail accounts.pdf Buy Old Gmail Accounts
 
Traction part 2 - EOS Model JAX Bridges.
Traction part 2 - EOS Model JAX Bridges.Traction part 2 - EOS Model JAX Bridges.
Traction part 2 - EOS Model JAX Bridges.
 
PSCC - Capability Statement Presentation
PSCC - Capability Statement PresentationPSCC - Capability Statement Presentation
PSCC - Capability Statement Presentation
 
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu Menza
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu MenzaYouth Involvement in an Innovative Coconut Value Chain by Mwalimu Menza
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu Menza
 

Intro to HTML5

  • 1. Short  intro  to  HTML5   Jussi  Pohjolainen   Tampere  University  of  Applied  Sciences  
  • 2.
  • 3.
  • 4.
  • 5.
  • 6. HTML5   •  Fi#h  version  of  HTML  standard  by  W3C   •  SCll  under  development  but  lot  of  browsers   support  the  proposal  of  the  standard   •  Simple  markup  that  can  be  wriFen  either  in   HTML  or  XHTML  syntax   •  PotenCal  candidate  for  cross  pla0orm  mobile   apps  
  • 7. HTML5   •  "Replacement  for  Flash"   –  See  comparison:     •  hFp://en.wikipedia.org/wiki/ Comparison_of_HTML5_and_Flash   •  HTML5  must  be  supplemented  with  other   technologies  like  CSS3  and  JS   –  HTML5  recommendaCon  specifies  html  markup  and   APIs  for  that  can  be  used  with  JS   •  Plan  is  to  have  HTML5  recommendaCon  by  the   end  of  2014  
  • 8. HTML5  vs  XHTML5   •  XHTML5  is  XML  serializaCon  of  HTML5   –  internet  media  type:  applica&on/xhtml+xml  or  applica&on/ xml   –  <!DOCTYPE  html>   •  HTML5   –  <!DOCTYPE  html>  opConal   •  HTML5  uses  polyglot  markup   –  valid  HTML  document  and  well-­‐formed  XML  document   –  Certain  elements  are  wriFen  using  minimized  tag  <br/>   –  And  certain  not:  <p></p>   –  hFp://dev.w3.org/html5/html-­‐xhtml-­‐author-­‐guide/html-­‐ xhtml-­‐authoring-­‐guide.html#empty-­‐elements  
  • 9. Minimal  HTML5  document   <!-- XML declaration is required --> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> </title> <!-- UTF-8 is recommended --> <meta charset="UTF-8" /> </head> <body> <svg xmlns="http://www.w3.org/2000/svg"> <rect stroke="black" fill="blue" x="45px" y="45px" width="200px" height="100px" stroke-width="2" /> </svg> </body> </html>
  • 10. What  is  New?   •  New  elements,  aFributes   –  SemanCc  elements,  HTML5  Forms   •  Video  and  audio   –  Lot  easier  to  show  <video>  and  <audio>   •  2D/3D  Graphics   –  <canvas>  -­‐  element,  inline  SVG,  CSS  2D/3D   •  New  APIs   –  Data  storage,  SQL  Database,  JS  workers  
  • 11. Video   <video width="320" height="240" controls="controls"> <source src="scroll_indicator.mp4" type="video/mp4"> <source src="scroll_indicator.ogg" type="video/ogg"> Your browser does not support the video tag. </video>
  • 12. SemanCc  Elements   •  Before   –  <div  id="header">..</div>   •  Now   –  <secCon>,  <arCcle>,  <header>,  <nav>  
  • 13. Exercise   •  Implement  HTML5  document  and  use  the  new   features:   –  header,  footer,  video,  arCcle,  secCon,  hgroup,   aside,  figure,  figcapCon,  Cme,  mark,  wbr,     •  See:   –  hFp://www.html-­‐5-­‐tutorial.com/  
  • 14. APIs   •  APIs  and  DOM  is  fundamental  part  of  the   specificaCon   •  APIs   –  Offline  Web  apps   –  Drag  and  drop   –  GeolocaCon   –  Web  SQL  database   –  …  
  • 15. GeolocaCon  API   •  GeolocaCon  API  SpecificaCon   –  hFp://dev.w3.org/geo/api/spec-­‐source.html   •  To  detect  the  locaCon  of  the  client   •  In  mobile:  GPS,  in  desktop  IP-­‐address  or  Wi-­‐Fi   locaCon  
  • 16. Browser  Support   •  IE9   •  Firefox  3.5   •  Chrome  5   •  Opera  10.6   •  Safari  5   •  iPhone  3   •  Android  2   •  WP  7.5  
  • 17. function setText(val, e) { document.getElementById(e).value = val; } function insertText(val, e) { document.getElementById(e).value += val; } var nav = null; function requestPosition() { if (nav == null) { nav = window.navigator; } if (nav != null) { var geoloc = nav.geolocation; if (geoloc != null) { geoloc.getCurrentPosition(successCallback); } else { alert("geolocation not supported"); } } else { alert("Navigator not found"); } } function successCallback(position) { alert("" + position.coords.latitude + ", " + position.coords.longitude); }
  • 18. Showing  Map  on  Google  API   •  hFp://maps.googleapis.com/maps/api/ staCcmap? center=<laCtude>,<longitude>&zoom=10&siz e=200x200&maptype=roadmap   •  See:     –  hFps://developers.google.com/maps/ documentaCon/staCcmaps/  
  • 19. Wunderground  +  GeolocaCon  +   Google  staCc  map   •  Wunderground  provides  JSON  API  for  weather   informaCon   •  Get  locaCon  of  the  browser  and  AJAX  request   to  wunderground   •  Aqer  receiving  the  result,  parse  it  and  show   results  in  html.   •  Problem:  AJAX  does  not  work  cross  site..  You   can  implement  middleware  (PHP)  
  • 20. Mobile  App  (iPhone)   Web  app!  
  • 22. Canvas   •  “The  canvas  element  a  resolu&on-­‐dependent   bitmap  canvas,  which  can  be  used  for   dynamically  rendering  of  images  such  as  game   graphics,  graphs,  or  other  images”   •  Image  is  drawn  in  JavaScript  using  typical  vector   graphics  drawing  primiCves   –  drawImage(),  lineTo(),  arcTo(),  bezierCurveTo(),   fillRect(),  scale(),  rotate(),  translate(),   createLinearGradient(),  shadowBlur(),  …    
  • 23. Simple  Drawing  using  Canvas  and  JS   <canvas id="mycanvas" width="200" height="200"> </canvas> <script> var canvas= document.getElementById('mycanvas'); var context = canvas.getContext('2d'); context.fillRect(60,30,80,120); </script>
  • 24. PossibiliCes   •  Simple  shapes  (Rectangles)   •  Complex  shapes  (Paths)     •  Lines   •  Shadows   •  Text   •  Images   •  Pixel  manipulaCon   •  Colors  and  styles   •  ComposiCng   •  TransformaCons   •  Canvas  state    
  • 26. main   function main() { createCanvas(); // Original position reset(); // Millisecs elapsed since 1970. then = Date.now(); loadImages(); setEventListeners(); //The setInterval() method calls a function or evaluates an expression at //specified intervals (in milliseconds). setInterval(gameLoop, 1); } window.onload=function(){ main(); }
  • 27. Game  Objects  and  Global  Variables   var keysDown = {}; var bgImage = null; var canvas = null; var ctx = null; var then; var monstersCaught = 0; // Game objects var hero = { speed: 256, x: 0, y: 0, myImage: null }; var monster = { x: 0, y: 0, myImage: null };
  • 28. Game  Loop   function gameLoop () { var now = Date.now(); var delta = now - then; update(delta / 1000); render(); then = now; };
  • 29. Create  Canvas   function createCanvas() { // Create canvas element canvas = document.createElement("canvas"); // Get the canvas object that you can use to draw ctx = canvas.getContext("2d"); // Set size for the canvas object canvas.width = 512; canvas.height = 480; document.getElementById("here").appendChild(canvas); }
  • 30. StarCng  point   function reset() { hero.x = canvas.width / 2; hero.y = canvas.height / 2; // Throw the monster somewhere on the screen randomly monster.x = 32 + (Math.random() * (canvas.width - 64)); monster.y = 32 + (Math.random() * (canvas.height - 64)); };
  • 31. Load  Image   function loadImage(imageSrc) { var image = new Image(); image.src = imageSrc; return image; } function loadImages() { hero.myImage = loadImage("lib/hero.png"); monster.myImage = loadImage("lib/monster.png"); bgImage = loadImage("lib/background.jpg"); }
  • 32. Key  Listeners   function setEventListeners() { // If keydown, then add the key to the array and set it true addEventListener("keydown", function (e) { keysDown[e.keyCode] = true; }, false); // If keyup, remove it from the array addEventListener("keyup", function (e) { delete keysDown[e.keyCode]; }, false); }
  • 33. Update   function update (modifier) { if (38 in keysDown) { // Player holding up hero.y -= hero.speed * modifier; } if (40 in keysDown) { // Player holding down hero.y += hero.speed * modifier; } if (37 in keysDown) { // Player holding left hero.x -= hero.speed * modifier; } if (39 in keysDown) { // Player holding right hero.x += hero.speed * modifier; } // Are they touching? if ( hero.x <= (monster.x + 32) && monster.x <= (hero.x + 32) && hero.y <= (monster.y + 32) && monster.y <= (hero.y + 32) ) { ++monstersCaught; reset(); } };
  • 34. Render   function render() { ctx.drawImage(bgImage, 0, 0); ctx.drawImage(hero.myImage, hero.x, hero.y); ctx.drawImage(monster.myImage, monster.x, monster.y); // Score ctx.fillStyle = "rgb(250, 250, 250)"; ctx.font = "12px Helvetica"; ctx.textAlign = "left"; ctx.textBaseline = "top"; ctx.fillText("FB Monsters caught: " + monstersCaught, 20, 20); };

Notas del editor

  1. &lt;!DOCTYPE html&gt; &lt;html&gt;&lt;head&gt;&lt;title&gt;Geolocation API Example&lt;/title&gt;&lt;script type=&quot;text/javascript&quot;&gt;function setText(val, e) {document.getElementById(e).value = val;}function insertText(val, e) {document.getElementById(e).value += val;}varnav = null; function requestPosition() { if (nav == null) {nav = window.navigator; } if (nav != null) {vargeoloc = nav.geolocation; if (geoloc != null) {geoloc.getCurrentPosition(successCallback); } else { alert(&quot;geolocation not supported&quot;); } } else { alert(&quot;Navigator not found&quot;); }}function successCallback(position){ alert(&quot;&quot; + position.coords.latitude + &quot;, &quot; + position.coords.longitude);}&lt;/script&gt;&lt;/head&gt;&lt;body&gt;&lt;input type=&quot;button&quot; onclick=&quot;requestPosition()&quot; value=&quot;Get Latitude and Longitude&quot; /&gt; &lt;/body&gt;&lt;/html&gt;
  2. // If on sec has passed, modifier is 1. If 0.5 secs has // passed, modifier is 0.5. // Using modifier, hero moves same speed no matter how // fast the update is called..