Top Banner
MULTI-SCREEN HTML5 Ron Reiter
57

Multi screen HTML5

Nov 05, 2014

Download

Technology

Ron Reiter

Learn how to design responsive HTML5 websites and applications, and learn how to choose the right tool for the job.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Multi screen HTML5

MULTI-SCREEN HTML5

Ron Reiter

Page 2: Multi screen HTML5

Who am I?

•  Ron Reiter •  HTML5 Google Developer

Expert •  HTML5-IL •  Consultant, Freelancer

Page 3: Multi screen HTML5

HTML5 != WEB

•  HTML5 is a platform for writing applications

•  Browser + Server = Web

!=  

Page 4: Multi screen HTML5

Why mobile web? •  Global mobile traffic now represents roughly 13% of Internet traffic •  Gartner research: In 2013 more than half of users will surf the web via

smartphones •  Nearly 1/3 of UK page views are from mobiles and tablets

BECAUSE YOU NEED TO DO IT

Page 5: Multi screen HTML5

Why HTML5?

•  Cross platform development •  FirefoxOS •  PhoneGap •  Desktops run JavaScript with great

performance •  Devices are only getting stronger

(Zuckerberg, kiss my *ss)

Page 6: Multi screen HTML5

Why NOT HTML5?

•  Millisecond grade interaction and animations •  HTML5 is not quite there yet

Page 7: Multi screen HTML5

Why Multi-screen?

Page 8: Multi screen HTML5

OK, I WANT MULTISCREEN

Page 9: Multi screen HTML5

CSS Media Queries

Page 10: Multi screen HTML5

CSS Media Queries - Before

$(window).resize(  function()  {          if  ($(window).width()  <  480)  {              document.body.className  =  “smartphone”;          }  else  if  ($(window).width()  >=  480  &&  $(window).width()  <  940)  {              document.body.className  =  “tablet”;          }  else  {              document.body.className  =  “desktop”;          }    });  

Page 11: Multi screen HTML5

CSS Media Queries - After

@media  (max-­‐width:  479px)  {    }    @media  (min-­‐width:  480px)  and  (max-­‐width:  939px)  {    }    @media  (min-­‐width:  940px)  {    }      

Page 12: Multi screen HTML5

CSS Media Queries - After

<link  rel="stylesheet"        type="text/css"  media="screen"  href="sans-­‐serif.css">    <link  rel="stylesheet"        type="text/css"  media="print"  href="serif.css">  

Page 13: Multi screen HTML5

CSS Media Queries - After

@import  url(responsive-­‐retina.css)  (-­‐webkit-­‐min-­‐device-­‐pixel-­‐ratio:  1.5),  (min-­‐resolution:  144dpi);  

Page 14: Multi screen HTML5

Important media queries

•  print  /  screen  •  orientation  •  min-­‐width  •  max-­‐width  •  min-­‐device-­‐width  •  max-­‐device-­‐width  •  -­‐webkit-­‐min-­‐device-­‐pixel-­‐ratio    /  min-­‐resolution  

 

Page 15: Multi screen HTML5

Why is this better?

•  Declarative CSS allows hardware acceleration •  Browser Optimizations •  Less ugly

Page 16: Multi screen HTML5

Viewport meta tag

•  This viewport tag disables mobile viewport resizing: <meta  name="viewport”  content=”          width=device-­‐width,  initial-­‐scale=1.0,  maximum-­‐scale=1.0,  user-­‐scalable=no  ”>  

•  Use it when you build responsive interfaces

Page 17: Multi screen HTML5

http://mediaqueri.es

Page 18: Multi screen HTML5

App or mobile web?

•  You already have your website, and now you want to support mobile devices.

•  Website – Easier maintenance

•  Application – More abilities

Page 19: Multi screen HTML5

What are my options?

•  Change your current website to a responsive web site

•  Your original website + Special website for tablets and smartphones

•  Just make an app (HTML5, native, etc).

Page 20: Multi screen HTML5

Responsive web UI Frameworks

Responsive  Web  Sites  Twi$er  Bootstrap  

Mobile  First  jQuery  Mobile  

Page 21: Multi screen HTML5

HTML5 Mobile First Applications

Page 22: Multi screen HTML5

Mobile First Web Applications

•  Make a mobile website •  Mobile application development platform

jQuery  Mobile   Sencha  Touch   jqMobi  

Backbone.js   Ember.js   Angular.js  

jQuery,  Zepto  

UI  Frameworks  

MVC  Frameworks  

DOM  ManipulaMon  Frameworks  

Page 23: Multi screen HTML5

jQuery Mobile

•  Amazing mobile framework •  Themable •  Cross Platform •  Around for a while

Page 24: Multi screen HTML5

jQuery Mobile Prototyping - Codiqa

Page 25: Multi screen HTML5

How to start

•  Create a new HTML page with: <link  rel="stylesheet"  href="http://code.jquery.com/mobile/1.3.0/jquery.mobile-­‐1.3.0.min.css"  />  

<script  src="http://code.jquery.com/jquery-­‐1.8.2.min.js"></script>  

<script  src="http://code.jquery.com/mobile/1.3.0/jquery.mobile-­‐1.3.0.min.js"></script>  

•  Or use Codiqa to download your app

Page 26: Multi screen HTML5

How to use jQuery Mobile

Page 27: Multi screen HTML5

What can jQuery Mobile do?

Page 28: Multi screen HTML5

jQuery Mobile

•  What can I do with jQuery mobile? •  Go to http://view.jquerymobile.com/1.3.0/

using your smartphone or tablet

Page 29: Multi screen HTML5

Responsive Applications

Page 30: Multi screen HTML5

Responsive Applications

Page 31: Multi screen HTML5

Responsive Applications

Page 32: Multi screen HTML5

Reflow Tables (web)

Page 33: Multi screen HTML5

Reflow Tables (mobile)

Page 34: Multi screen HTML5

jQuery Mobile Architecture & Navigation

Page 35: Multi screen HTML5

jQuery Mobile Architecture

AJAX  /  Preloaded One  HTML,  Two  pages  

Web  NavigaMon  Two  HTMLs,  Two  pages  

Page 36: Multi screen HTML5

AJAX Navigation

•  Instead of changing the document location, we use $.mobile.navigate (saves history) $(“a”).on(“click”,  function(  event  )  {    event.preventDefault();    $.mobile.navigate  (  this.attr(“href”)  );  

});  

Page 37: Multi screen HTML5

AJAX Navigation

•  Once we navigate, a “navigate” event is fired  $(window).on(“navigate”,  function(event,  data)  {          //  load  new  content  using  AJAX  });  

Page 38: Multi screen HTML5

Navigating between loaded pages

JavaScript:  $.mobile.changePage(“#page2”,  “pop”,  false,  true);  $.mobile.back();  

HTML:  <div  data-­‐role=“page”  id=“page1”></div>  <div  data-­‐role=“page”  id=“page2”></div>  

Page 39: Multi screen HTML5

Creating a page dynamically

JavaScript:    $(document.body).append('<div  data-­‐role="page"  id=”page2"><div  data-­‐role="content">'  +  content  +  '</div></div>');  $.mobile.initializePage();  $.mobile.changePage(“#page2”,  “pop”,  false,  true);  

Page 40: Multi screen HTML5

jQuery Mobile + MVC

•  Angular – https://github.com/tigbro/jquery-mobile-angular-

adapter

•  Backbone – we need a special router – https://github.com/azicchetti/jquerymobile-router

•  Ember + jQuery Mobile is a bit harder since both frameworks utilize a fair amount of voodoo

Page 41: Multi screen HTML5

OK, I want an app!

•  PhoneGap / Apache Cordova – Gives native API access from JavaScript

•  PhoneGap was bought by Adobe, so that non-Adobe development is done in Cordova

Page 42: Multi screen HTML5

PhoneGap Build

•  Removes the need for compiling to all platforms

Page 43: Multi screen HTML5

Desktop?

Page 44: Multi screen HTML5

Responsive Web Design

Page 45: Multi screen HTML5

Responsive Web Design

•  Web sites with a simple UI need to adapt to multiple screen form factors

•  Web sites are less complicated than web applications, but still very similar

•  jQuery mobile is also a tool for responsive web design – http://view.jquerymobile.com/1.3.0/docs/intro/

rwd.php

Page 46: Multi screen HTML5

Twitter Bootstrap

Page 47: Multi screen HTML5

Twitter Bootstrap

•  UI framework is more straightforward than jQuery Mobile

•  The UI elements are not as good for mobile as jQuery Mobile

•  Mobile browsers do not behave well with advanced Bootstrap UI elements like jQuery Mobile does

Page 48: Multi screen HTML5

How to make Bootstrap responsive?

•  Add this to your Bootstrap app: <meta  name="viewport"  content="width=device-­‐width,  initial-­‐scale=1.0">  <link  href="assets/css/bootstrap-­‐responsive.css"  rel="stylesheet">  

•  And you’re ready to go!

Page 49: Multi screen HTML5

Twitter Bootstrap Grid

<div  class=“container”>      <div  class=“row”>  <!-­‐-­‐  columns  must  sum  up  to  12  -­‐-­‐>          <div  class=“span4”>  …  content  …  </div>          <div  class=“span4”>  …  content  …  </div>                  <div  class=“span4”>  …  content  …  </div>      </div>  </div>  

Page 50: Multi screen HTML5

Bootstrap Grid (web)

span4   span4   span4  

Page 51: Multi screen HTML5

Bootstrap Grid (mobile)

span4  

span4  

span4  

Page 52: Multi screen HTML5

Example (web)

Page 53: Multi screen HTML5

Example (mobile)

Page 54: Multi screen HTML5

Initializr

Page 55: Multi screen HTML5

Responsive Design Bookmarklet���http://responsive.victorcoulon.fr/

Page 56: Multi screen HTML5

Viewport Resizer���http://lab.maltewassermann.com/viewport-resizer/

Page 57: Multi screen HTML5

THANK YOU!