Top Banner
The Future of Responsive Design Standards Standards will evolve to better adapt to our users' needs and environments. November 5, 2014
47

The Future of Responsive Design Standards

Jul 14, 2015

Download

Documents

Brian Fegan
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: The Future of Responsive Design Standards

The Future of ResponsiveDesign Standards

Standards will evolve to better adapt to our users'needs and environments.

November 5, 2014

Page 2: The Future of Responsive Design Standards

Brian FeganAssociate Director ofCreative Development

Page 3: The Future of Responsive Design Standards

How would you...include additional HTML at larger breakpoints?serve high resolution video based on a user's connection speed?increase text size based on a user's distance to the screen?adapt layouts and fonts based on a user's region?

Page 4: The Future of Responsive Design Standards

One Site Fits All

Page 5: The Future of Responsive Design Standards

User Agent Detection

if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) { $('body').addClass('mobile'); } else { $('body').addClass('desktop'); }

.desktop .button { height:1em; } .mobile .button { height:2em; }

Page 6: The Future of Responsive Design Standards

Viewport CSS Classes

var $body = $('body'); $(window).resize(function(){ var width = $body.width() if (width < 480) { $body.addClass('mobile'); } else { $body.addClass('desktop'); } });

.desktop .button { height:1em; } .mobile .button { height:2em; }

Page 7: The Future of Responsive Design Standards

Media Queries!

@media only screen and (max-width: 480px) { /* insert magic here */ }

Page 8: The Future of Responsive Design Standards

Now What?Reduce JavascriptEvolve HTML and CSSThink Beyond the Browser

Page 9: The Future of Responsive Design Standards

Reduce JavaScriptManaging input deviceGeolocationRetrieving additional content and imagesInterfacing with SDKs and HTML5 Device APIs

Page 10: The Future of Responsive Design Standards

Evolving HTML

Page 11: The Future of Responsive Design Standards

Responsive ImagesAdaptive Images (.htaccess, PHP)Cookie-based solution (JS, PHP)Pure JavaScript Replacement

$('div.img').responsiveImages( {large:'1025px', medium:'481px'} );

<div class="img" data-src-lg="lg.jpg" data-src-md="md.jpg" data-src="def.jpg"></div> <noscript><img src="default.jpg" alt="SEO Alt Tag" /></noscript>

Page 12: The Future of Responsive Design Standards

The <picture> Element

<picture> <source srcset="large.jpg" media="(min-width:1025px)"> <source srcset="medium.jpg" media="(min-width:481px)"> <source srcset="small.jpg"> <img src="fallback.jpg" alt="SEO Alt Tag"> </picture>

Page 13: The Future of Responsive Design Standards

How would you......include additional HTML at larger breakpoints?

Page 14: The Future of Responsive Design Standards

AJAX

var hasSidebar = false; var $body = $(body); var $window = $(window); function addSidebar() { if ($body.hasClass('desktop')) { hasSidebar = true; $window.off('resize.sidebar'); $.ajax({ url: 'sidebar.html', success: function(html) { $('#sidebar').append(html); } }); } } $window.on('resize.sidebar', addSidebar); addSidebar();

Page 15: The Future of Responsive Design Standards

Link tags could work for HTML

<link href="sidebar.html" for="sidebar" rel="html" media="(min-width: 40em)"> <aside id="sidebar">...</aside>

A link tag plus media query could include an HTML fileSearch engines would be able to access it

Page 16: The Future of Responsive Design Standards

Evolving CSS

Page 17: The Future of Responsive Design Standards

Level 4 Media Queriesscripting: enabled, none, or intitial-onlyhover/any-hover: none, hover, or on-demandpointer/any-pointer: none, coarse or finelight-level: dim, normal or washed

Page 18: The Future of Responsive Design Standards

<noscript>

<head> <noscript> <link href="noscript.css" rel="stylesheet" /> </noscript> </head> <body> <div class="js-content"> <!-- Some content injected via JavaScript --> </div> <noscript> Oops, no JavaScript for you. </noscript> </body>

Page 19: The Future of Responsive Design Standards

Scripting Media Query

<!-- compliment a noscript tag here --> <link href="noscript.css" rel="stylesheet" media="not (scripting)"> <!-- or replace noscript tags --> <link href="noscript.html" for="sidebar" rel="html" media="not (scripting)"> <aside id="noscript">...</aside>

Page 20: The Future of Responsive Design Standards

Has Touch?

if ('ontouchstart' in window) { $('body').addClass('has-touch'); } else { $('body').addClass('no-touch'); }

.no-touch { /* hover styles */ }

Page 21: The Future of Responsive Design Standards

Hover Media Query

@media only screen and (any-hover) { /* hover styles */ }

Page 22: The Future of Responsive Design Standards

Pointer Media Query

@media only screen and not (any-pointer) { /* touch input styles */ } @media only screen and (pointer:coarse) { /* wii controller styles */ }

Page 23: The Future of Responsive Design Standards

Ambient Light Events API

$(window).on('devicelight', function(e) { if (e.value < 50) { $('body').addClass('dim'); } else if (e.value < 10000) { $('body').addClass('normal'); } else { $('body').addClass('bright'); } });

body.bright { /* bright styles */ }

Page 24: The Future of Responsive Design Standards

Light-Level Media Query

@media screen and (light-level: washed) { /* washed styles */ }

Page 25: The Future of Responsive Design Standards

Device & Network APIsas Media Queries

connection-metered: none or connection-meteredconnection-bandwidth: measured in Mbsproximity: meters from sensoruser-media: none, audio, or videonetwork-discovery: none or network-discovery

Page 26: The Future of Responsive Design Standards

How would you......serve high resolution video based on a user's connection speed?

Page 27: The Future of Responsive Design Standards

Dirty Network Speed Check

// load a 2MB image and check the time diff var ts = new Date().getTime(); $('<img>').attr('src','test.jpg').on('load', function(){ var diff = (new Date().getTime()) - ts; if (diff < 1000) { // slow } else { // fast } });

Page 28: The Future of Responsive Design Standards

Network Information API

var connection = (navigator.connection || navigator.mozConnection || navigator.webkitConnection); if (connection && !connection.metered && connection.bandwidth > 2) { $('body').addClass('hi-rez'); } else $('body').addClass('low-rez'); }

Page 29: The Future of Responsive Design Standards

Connection Media Queries

@media screen and not connection-metered and (min-connection-bandwidth: 2Mbs) { /* hi-rez media */ }

Page 30: The Future of Responsive Design Standards

How would you......increase text size based on a user's distance to the screen?

Page 31: The Future of Responsive Design Standards

Proximity Events API

$(window).on('deviceproximity', function(e) { if ( (e.value / 100) > 3 ) { $(body).addClass('distant'); } else { $(body).addClass('near'); } });

Page 32: The Future of Responsive Design Standards

Proximity Media Query

@media screen and (min-proximity: 3m) { /* far from screen styles */ }

Page 33: The Future of Responsive Design Standards

Get User Media API

if (navigator.getUserMedia) { navigator.getUserMedia ( { video:true, audio:true }, function(localMediaStream) { var video = document.querySelector('video'); video.src = window.URL.createObjectURL(localMediaStream); // Do something with the video here, e.g. video.play() }, function(err) { console.log("The following error occured: " + err); } ); } else { console.log("getUserMedia not supported"); }

Page 34: The Future of Responsive Design Standards

User Media Media Query

<link href="video.css" rel="stylesheet" media="(user-media: video)"> <link href="audio.css" rel="stylesheet" media="(user-media: audio)">

Page 35: The Future of Responsive Design Standards

Network Service Discovery API

function showServices( services ) { // Show a list of all the services provided for(var i = 0, l = services.length; i < l; i++) console.log( services[i].name + '(' + services[i].type + ')' ); } navigator.getNetworkServices([ 'zeroconf:_boxee-jsonrpc._tcp', 'upnp:urn:schemas-upnp-org:service:ContentDirectory:1' ]).then(showServices);

Page 36: The Future of Responsive Design Standards

Network Discovery Media Query

.remote-control { display: none; } @media screen and (network-discovery) { .remote-control { display: block; } }

Page 37: The Future of Responsive Design Standards

Evolving Media Queriesregion: country codesspeed: meters per secondsound-level: normal, loud, or headset

Page 38: The Future of Responsive Design Standards

How would you......adapt layouts and fonts based on a user's region?

Page 39: The Future of Responsive Design Standards

navigator.geolocation

if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(function (position) { console.log('Latitude: ' + position.coords.latitude); console.log('Longitude: ' + position.coords.longitude); // inject google maps... // call reverse geocode service to obtain country code... }); } else { console.log('No geolocation for you!); }

Page 40: The Future of Responsive Design Standards

IP Detection Service

<script src="http://ip-detection.com/service.js"></script> ... var country = geoip_country_code(); if (country == 'RU') { $('head').append('<link href="russian.css" rel="stylesheet">'); }

Page 41: The Future of Responsive Design Standards

Region Media Query

<!-- only include russian language styles --> <link href="russian.css" rel="stylesheet" media="(region: RU)">

Page 42: The Future of Responsive Design Standards

Speed Media Query

@media screen and (min-speed: 3m/s) { /* if walking, jogging or running */ }

Page 43: The Future of Responsive Design Standards

Sound Level Media Query

@media screen and (sound-level: loud) { /* hide media or prompt user to plug in headphones */ }

Page 44: The Future of Responsive Design Standards

Beyond the Browser

Page 45: The Future of Responsive Design Standards

Emotion Markup Language

@media screen and emotion and (emotion-level: happy) { /* rainbow and unicorn styles */ }

Page 46: The Future of Responsive Design Standards

Be Curious

Page 47: The Future of Responsive Design Standards

Thank You@feganb

[email protected]/in/feganbrian/