28
Mobile HTML5 Today! Ido Green Developer Advocate Google 2014

Mobile html5 today

Embed Size (px)

DESCRIPTION

What are some of the important features we can use today on mobile web browsers? How HTML5 can help our users to be more productive? Some of the answers are in these slides.

Citation preview

Page 1: Mobile html5 today

Mobile HTML5 Today!

Ido GreenDeveloper Advocate Google 2014

Page 2: Mobile html5 today

Ido GreenDeveloper AdvocateGoogle

Who?!

plus.google.com/greenido

greenido.wordpress.com

Page 3: Mobile html5 today

Who has a smartphone?

Page 4: Mobile html5 today

Who loves typing on a phone?

Page 5: Mobile html5 today

Who uses their phone as a desktop?

Page 6: Mobile html5 today

● The screens are smaller

● Users are mobile

● Input. is. harder.

● Unique hardware capabilities

● Everything is slower

Mobile is different

Page 7: Mobile html5 today

The screens are smaller.

What can I do?

Page 8: Mobile html5 today

A LOT!

Page 9: Mobile html5 today

The critical element for mobile!

Device width:

<meta name="viewport" content="width=device-width" />

Initial scale:

<meta name="viewport" content="initial-scale=1.0" />

<meta name="viewport"

content="width=device-width, initial-scale=1.0" />

Video And Demo: goo.gl/j9KLT

Viewport

Page 10: Mobile html5 today

Adaptive to screen size

@media screen and (min-width: 800px) { ... }

@media screen and (device-aspect-ratio: 16/9) { ... }

@media screen and (resolution: 2dppx) { ... }

● Logically group your styling rules.

● Dynamically responsive.

Media Queries

Page 11: Mobile html5 today

Mobile devices can usually be rotated

@media screen and (orientation: portrait) {}

@media screen and (orientation: landscape) {}

Video And Demo: goo.gl/SgMEo

Orientation

Page 12: Mobile html5 today

Sizing relatively to the viewport

#visible-square {

width: 20vmin;

height: 20vmin;

}

● Four new units: vw(idth), vh(eight),

vmin and vmax.

● Relative to the size of the viewport

(!) Value is 1% of width/height of the viewport1vw = 1% of the viewport width

1vh = 1% of viewport height

Video And Demo: goo.gl/J5tna

Viewport units

Page 13: Mobile html5 today

Users Are Mobile

Page 14: Mobile html5 today

Request the current position once

var success = function(position) {

var lat = position.coords.latitude;

var long = position.coords.longitude;

};

navigator.geolocation.getCurrentPosition(success);

Or keep track when they're on the move!

var watchId = navigator.geolocation.watchPosition(

function (position) { ... }); // Stop watching when you're done.

clearWatch(watchId);

Geolocation

Page 15: Mobile html5 today

Events when the device's orientation changes

window.onorientationchange = function(event) {

var yaw = event.alpha;

var pitch = event.beta;

var roll = event.gamma;

// You could make a compass!

}

Video And Demo: goo.gl/zNvp3

Device Orientation

Page 16: Mobile html5 today

Determine the network state

window.navigator.onLine

window.addEventListener("online", function() {

console.log("Visitor *might* be online.");

});

window.addEventListener("offline", function() {

console.log("Visitor is definitely offline.");

});

● Very hard to know for sure whether the visitor is online.● Check my demo: picturesque-app.appspot.com

Video And Demo: goo.gl/Bgmcp

Offline Events

Page 17: Mobile html5 today

<html manifest="website.manifest">

CACHE MANIFEST#version 1.2013.5.16css/bootstrap.min.css

#Imagesimg/logo.png

● Will also be used when the user is online.● Allows you to define fallback pages.● Don't cache the manifest!

Video And Demo: goo.gl/3fO2I

Application Cache

Page 18: Mobile html5 today

Use abstractions:

● Lawn Chair - brian.io/lawnchair/

● asyncStorage - https://github.com/WebReflection/db

● IndexedDBShim - nparashuram.com/IndexedDBShim/

Storage APIs

Page 19: Mobile html5 today

Input. Is. Harder!

What can I do?

Page 20: Mobile html5 today

Specialized on-screen keyboards<input type="email" />

<input type="search" />

<input type="url" />

<input type="tel" />

<input type="number" />

<input type="date" />

<input type="week" />

<input type="month" />

<input type="datetime-local" />

Video And Demo: goo.gl/CNMp6

Semantic input types

Page 21: Mobile html5 today

Touch EventsHandle the visitor's touches

[element].ontouchstart = function(ev){};

[element].ontouchmove = function(ev){};

[element].ontouchend = function(ev){};

(!) Warning: 300 millisecond click delay → Use FastClick

Docs: goo.gl/8ybb5Video And Demo: goo.gl/ZwOzk

Page 22: Mobile html5 today

Unique Hardware capabilities

What can I do?

Page 23: Mobile html5 today

Camera - Media CaptureTake photos<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 - Let’s go wild...

}

}

Video And Demo: picturesque-app.appspot.com

Page 24: Mobile html5 today

getUserMedia

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();

});

Demo: ido-green.appspot.com/getUserMedia-hello-world.htmland a short Video.

Page 25: Mobile html5 today

Android Intents

Interacting with native appsintent:

HOST/URI-path // Optional host

#Intent;

package=[string];

action=[string];

category=[ string];

component=[ string];

scheme=[string];

end;

<a

href="intent://scan/#Intent;scheme=zxing;package=com.google.zxing.client.android;end" >

Take a QR code

</a>

More information:developers.google.com/chrome/mobile/docs/intents

Video And Demo: goo.gl/Kpk0C

Page 26: Mobile html5 today

Well...

What can I do?

Page 27: Mobile html5 today

What We Can Do Today?● Adapt to screen sizes

● Accommodate users on the move

● Speed up input

● Integrate with device features

● Measure performance across all devices

● Look forward to WebRTC, Web Audio and WebGL