Mobile Web
The Power of HTML5
Mobile Forum Stuttgart, 17.05.2013
Sven Wolfermann | maddesigns
The Power of HTML5
Mobile Forum Stuttgart, 17.05.2013
Sven Wolfermann | maddesigns
HTML 2.0 | 1995 |
---|---|
HTML 3.2 | 1997 |
HTML 4.0 | 1997 |
HTML 4.01 | 1999 |
XHTML 1.0 | 2000 |
---|---|
XHTML 1.1 | 2001 |
XHTML 2 |
HTML 5.0 | HTML 5.1 | HTML 5.2 | |
---|---|---|---|
2012 | Candidate Rec | 1st WD | |
2013 | Call for Review | ||
2014 | Recommendation | Last Call | |
2015 | Candidate Rec | 1st WD | |
2016 | Recommendation | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!DOCTYPE html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<?xml version="1.0" encoding="UTF-8"?> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="file.css"> <style type="text/css"></style> <script type="text/javascript"></script>
<link rel="stylesheet" href="file.css"> <style></style> <script></script>
<h2> <a href="/path/to/resource">Headline text</a> </h2> <p> <a href="/path/to/resource">Paragraph text.</a> </p>
<a href="/path/to/resource"> <h2>Headline text</h2> <p>Paragraph text.</p> </a>
neue Elemente für bessere Semantik
article, aside, audio, bdi, canvas, command, data, datalist, details, embed, figcaption, figure, footer, header, hgroup, keygen, mark, meter, nav, output, progress, rp, rt, ruby, section, source, summary, time, track, video, wbr
hgroup – nicht mehr in HTML5.1
dates, times, email, url, search, number, range, tel, color
<body> <div id="header">...</div> <div id="navigation">...</div> <div id="main">...</div> <div id="sidebar">...</div> <div id="footer">...</div> </body>
<body> <header>...</header> <nav>...</nav> <div id="main">...</div> <aside>...</aside> <footer>...</footer> </body>
NEU in HTML5.1: <main>
(bereits in Firefox 21 unterstützt)
<meta name="viewport" content="width=device-width"> <!-- bzw. --> <meta name="viewport" content="width=device-width,initial-scale=1.0">
bald im CSS (Support für Opera Mobile, IE10)
@viewport { width: device-width; } /* IE10 mobile */ @media screen and (max-width:400px) { @-ms-viewport{ width: 320px; /* the viewport for small devices is set to 320px */ /* width: device-width is buggy in IE10 */ } }
<video src="video.ogv" controls autoplay poster="poster.jpg" width="320" height="240"> <a href="video.ogv">Download movie</a> </video>
H.264: weitverbreitet, aber Patente / Lizenz
Theora: lizenzfrei, aber nicht fürs Web optimiert
WebM:
neues Format, Opera, Firefox, Chrome, Android unterstützen es, Internet Explorer 9, Safari mit installiertem Codec
Ein WebM VP9 Video soll 50% kleiner als ein H.264 Video der gleichen Qualitätsstufe sein. In Chrome 29 stable ab 20. August 2013.
<video controls autoplay poster="…" width="…" height="…"> <source src="movie.webm" type="video/webm" /> <source src="movie.ogv" type="video/ogg" /> <source src="movie.mp4" type="video/mp4" /> <!-- fallback content --> </video> video.canPlayType('video/webm');
jQuery Elemente selektieren
$('.foo .bar')
nativ HTML5 ab IE8!
document.querySelector('.foo .bar') document.querySelectorAll('.foo .bar')
jQuery Suche innerhalb des Selektors
$(element).find('.bar')
nativ
element.querySelector('.bar')
jQuery Element Attribut setzen
$(element).attr(key, value)
nativ
element.setAttribute(key, value)
jQuery CSS Eigenschaften setzen
$(element).css(name, value)
nativ
element.style[name] = value
jQuery neues Element anlegen
var div = $('<div>')
nativ
var div = document.createElement('div')
jQuery Element anfügen
$(a).append(b)
native
a.appendChild(b)
jQuery Elementinhalt ändern
$(element).html(htmlString)
nativ
element.innerHTML = htmlString
jQuery Element entfernen
$(element).remove()
nativ
element.parentNode.removeChild(element)
jQuery HTML-Klasse zum <body> hinzufügen
$('body').addClass('hasJS');
nativ
document.body.classList.add('hasJS');
jQuery Klassen wechseln
$('div').toggleClass('my-class')
nativ
div.classList.toggle('visible'); //now it's added div.classList.toggle('visible'); //now it's removed
Chrome seit Version 4.0 (aktuell Version 26)
Firefox seit Version 3.5 (aktuell Version 21)
Opera / Mobile seit Version 10.0 (12.1 / 12.0)
Safari / iOS seit Version 3.1 / 3.2 (6.0 / 6.0)
Android seit Version 2.1 (4.2)
IE / mobile seit Version 8.0 / 9.0 (10.0 / 10.0)
weaning yourself off jquery
http://substack.net/weaning_yourself_off_jquery
I know jQuery. Now what?
http://remysharp.com/2013/04/19/i-know-jquery-now-what/
Moving from jQuery
(Cutting the mustard - BBC Webdev)
isModernBrowser: ( 'querySelector' in document && 'addEventListener' in window && 'localStorage' in window )
kann der Browser querySelector, addEventListener und localStorage, dann ist es ein moderner Browser
Browser Feature Detection
<progress> <meter> <datalist> <input type="text" placeholder="new placeholder attribute"> <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"> <input type="color"> <input type="range">
Foto mit dem Device aufnehmen
<input type="file" capture accepts="image/*" id="cam">
var cam = document.getElementById("cam"); cam.onchange = function(event) { // An image has been captured. if(event.target.files.length == 1 && event.target.files[0].type.indexOf("image/") == 0) { // We have an image, most likely from a camera } }
<input type="email">
<input type="email" required>
<input type="url">
<input type="date">
<input type="number">
<input type="text" pattern="[0-9]*">
[element].ontouchstart = function(event) {}; [element].ontouchmove = function(event) {}; [element].ontouchend = function(event) {};
onpointerdown, onpointerup, onpointermove, onpointerover, onpointerout, onpointerenter, onpointerleave.
localStorage.setItem("key1", "value1"); localStorage["key1"] = "value1";
localStorage.getItem("key1"); localStorage["key1"];
localStorage.removeItem("key1");
localStorage.length;
localStorage.clear();
Der Application Cache (AppCache) legt fest welche Dateien der Browser offline verfügbar machen soll.
<!DOCTYPE HTML> <html manifest="/my.manifest">
// my.manifest CACHE MANIFEST /my-hero-image.jpg /fallback.html ...
AddType text/cache-manifest .manifest
IE | Firefox | Safari | Chrome | Opera | iPhone | Android |
8+ | 3.5+ | 4.0+ | 4.0+ | 10.5+ | 2.0+ | 2.0+ |
Don't cache the manifest!
Standortdaten abfragen
if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(position); } else { alert("Geolocation wird nicht unterstützt"); }
Position auf GoogleMaps ausgeben
var longitude = position.coords.longitude; var latitude = position.coords.latitude; var pos = new google.maps.LatLng( position.coords.latitude, position.coords.longitude);
Rechteck zeichnen
function draw(){ var ctx = document.getElementById('canvas').getContext('2d'); ctx.fillRect(25,25,100,100); ctx.clearRect(45,45,60,60); ctx.strokeRect(50,50,50,50); }
function addClicker(link) { link.addEventListener("click", function(e) { swapPhoto(link.href); history.pushState(null, null, link.href); e.preventDefault(); }, false); }
history.pushState(null, null, link.href);
Inline camera and mic access
navigator.getUserMedia({audio:true, video: true}, function(stream) { // An image has been captured. video.src = URL.createObjectURL(stream); video.play(); });
Accessing the Device Camera with getUserMedia
WebRTC Video Chat z.B. zwischen Firefox und Chrome
jQuery 2.0 wurde leicht entschlackt und Polyfills für alte Browser entfernt
kein Support mehr für IE 6/7/8!
seit 1.8 möglich ein angepasstes Build zu erstellen
Zepto ist eine minimale JS-Library für moderne Browser
Funktionen wie bei jQuery
auch kein IE-Support
Fragen?
Sven Wolfermann | maddesigns