responsive navigation patterns - respond 2014

69
We can make people happy with Responsive Navigation Patterns

Upload: david-lewis

Post on 27-Jun-2015

833 views

Category:

Technology


0 download

DESCRIPTION

The slide deck I used at Respond 2014. The slides where the code is brought together originally used video to show the full experience, in this slide deck there is only a single image :( You can view the code samples prepared for this slide deck here: https://github.com/dp-lewis/respond

TRANSCRIPT

Page 1: Responsive Navigation Patterns - Respond 2014

We can make people happywith Responsive Navigation Patterns

Page 2: Responsive Navigation Patterns - Respond 2014

People want this

Page 3: Responsive Navigation Patterns - Respond 2014

“At first I was angry, but then sadness crept in as I realised that

I’m never going to be able to read those m***** f***ing comments”

a user of a popular US news site !

Page 4: Responsive Navigation Patterns - Respond 2014

There are a lot of patterns Some have been superseded

Page 5: Responsive Navigation Patterns - Respond 2014

The Footer Anchor

this menu button

Jumps you to the footer

Page 6: Responsive Navigation Patterns - Respond 2014

The Select Menu

this nav bar

turns into a select element

Page 7: Responsive Navigation Patterns - Respond 2014

How to make people happy 3 of the top navigation patterns

Page 8: Responsive Navigation Patterns - Respond 2014

1. Do (almost) Nothing 2. The Toggle 3. The Flyout

Page 9: Responsive Navigation Patterns - Respond 2014

1. Do (almost) Nothing also known at Top Nav

Page 10: Responsive Navigation Patterns - Respond 2014

Pros Easy to implement

No fancy CSS voodoo No JavaScript hocus pocus

!

Cons Doesn’t suit lots of items due to space

Do (Almost) Nothing

Page 11: Responsive Navigation Patterns - Respond 2014

Example of Do Nothing

simplebits.com

Page 12: Responsive Navigation Patterns - Respond 2014

What we’re going to build

Page 13: Responsive Navigation Patterns - Respond 2014

HTML

Page 14: Responsive Navigation Patterns - Respond 2014

HTML can be very basic !

<div class="brand">Logo</div> !<nav class="navbar"> <ul class="navbar--items"> <li><a href="home.html">Home</a></li> ... </ul> </nav> !<div class="content"> <h1>Do Nothing</h1> ... </div>

Page 15: Responsive Navigation Patterns - Respond 2014

CSS

Page 16: Responsive Navigation Patterns - Respond 2014

Small screen first !

.navbar,

.brand { text-align: center; }

Page 17: Responsive Navigation Patterns - Respond 2014

Align the navigation

.navbar,

.brand { text-align: center; } !.navbar--items li { display: inline-block; }

Page 18: Responsive Navigation Patterns - Respond 2014

Scaling up for larger screens

Page 19: Responsive Navigation Patterns - Respond 2014

Set a breakpoint for scaling up

@media screen and (min-width: 40em) {

Page 20: Responsive Navigation Patterns - Respond 2014

Re-align the brand and navbar !

@media screen and (min-width: 40em) { .brand { float: left; width: 20%; } .navbar { float: left; width: 80%; }

Page 21: Responsive Navigation Patterns - Respond 2014

Pad the navigation items !

@media screen and (min-width: 40em) { .brand { float: left; width: 20%; } .navbar { float: left; width: 80%; } .navbar--items li { padding-left: 5%; padding-right: 5%; } }

Page 22: Responsive Navigation Patterns - Respond 2014

Putting it all together !

Page 23: Responsive Navigation Patterns - Respond 2014

The Toggle

Page 24: Responsive Navigation Patterns - Respond 2014

Pros Keeps the user in place

Doesn’t take up room when not in use Easy to scale up

!

Cons Small JavaScript dependancy

Animation quality

The Toggle

Page 25: Responsive Navigation Patterns - Respond 2014

Example of the toggle

starbucks.com

Page 26: Responsive Navigation Patterns - Respond 2014

What we’re going to build

Page 27: Responsive Navigation Patterns - Respond 2014

HTML

Page 28: Responsive Navigation Patterns - Respond 2014

HTML is almost the same !

<button class="button-toggle" data-toggle>Menu</button> !<div class="brand">Logo</div> !<nav class="navbar"> <ul class="navbar--items"> ... </ul> </nav> ...

Page 29: Responsive Navigation Patterns - Respond 2014

JS

Page 30: Responsive Navigation Patterns - Respond 2014

Determine the type of event

var click = 'click'; !if (document.documentElement.hasOwnProperty('ontouchstart')) { click = 'touchstart'; }

Page 31: Responsive Navigation Patterns - Respond 2014

Select the elements with the attribute

var click = 'click'; !if (document.documentElement.hasOwnProperty('ontouchstart')) { click = 'touchstart'; } !var toggleButtons = document.querySelectorAll('[data-toggle]');

Page 32: Responsive Navigation Patterns - Respond 2014

Create a function to toggle the class

var click = 'click'; !if (document.documentElement.hasOwnProperty('ontouchstart')) { click = 'touchstart'; } !var toggleButtons = document.querySelectorAll('[data-toggle]'); !function toggle(ev) { ev.preventDefault(); ev.target.classList.toggle('is-on'); }

Page 33: Responsive Navigation Patterns - Respond 2014

Associate the elements with the function

var click = 'click'; !if (document.documentElement.hasOwnProperty('ontouchstart')) { click = 'touchstart'; } !var toggleButtons = document.querySelectorAll('[data-toggle]'); !function toggle(ev) { ev.preventDefault(); ev.target.classList.toggle('is-on'); } !/* Put everything togther */ for (var i = 0; i < toggleButtons.length; i = i + 1) { toggleButtons[i].addEventListener(click, toggle, false); }

Page 34: Responsive Navigation Patterns - Respond 2014

CSS

Page 35: Responsive Navigation Patterns - Respond 2014

CSS to hide the navigation !

.navbar { max-height: 0; overflow: hidden; transition: max-height ease-in 300ms; }

Page 36: Responsive Navigation Patterns - Respond 2014

CSS to show the navigation !

.navbar { max-height: 0; overflow: hidden; transition: max-height ease-in 300ms; } !.button-toggle.is-on { background: #222; } !.button-toggle.is-on ~ .navbar { max-height: 1000px; }

Page 37: Responsive Navigation Patterns - Respond 2014

Scaling up to larger screens

Page 38: Responsive Navigation Patterns - Respond 2014

Show the navigation !

@media screen and (min-width: 40em) { .navbar { max-height: 1000px; } !

Page 39: Responsive Navigation Patterns - Respond 2014

Hide the button !

@media screen and (min-width: 40em) { .navbar { max-height: 1000px; } ! .button-toggle { display: none; }

Page 40: Responsive Navigation Patterns - Respond 2014

Make the navigation display inline !

@media screen and (min-width: 40em) { .navbar { max-height: 1000px; } ! .button-toggle { display: none; } ! .navbar--items > li { display: inline-block; } }

Page 41: Responsive Navigation Patterns - Respond 2014

Putting it all together !

Page 42: Responsive Navigation Patterns - Respond 2014

Nav Flyout

Page 43: Responsive Navigation Patterns - Respond 2014

Pros Lots of space Wow factor

Popularised by Facebook !

Cons Performance

Device support Hard to scale

Nav Flyout

Page 44: Responsive Navigation Patterns - Respond 2014

Example !

tenplay.com.au

Page 45: Responsive Navigation Patterns - Respond 2014

What we’re going to build !

Page 46: Responsive Navigation Patterns - Respond 2014

HTML

Page 47: Responsive Navigation Patterns - Respond 2014

Same as toggle

Page 48: Responsive Navigation Patterns - Respond 2014

JS

Page 49: Responsive Navigation Patterns - Respond 2014

Same as toggle

Page 50: Responsive Navigation Patterns - Respond 2014

CSS

Page 51: Responsive Navigation Patterns - Respond 2014

Stretch the navigation .navbar { position: fixed; bottom: 0; right: 0; top: 0; width: 66%; padding-top: 3em; !

Page 52: Responsive Navigation Patterns - Respond 2014

Translate the navigation out the way .navbar { position: fixed; bottom: 0; right: 0; top: 0; width: 66%; padding-top: 3em; transform: translate(100%, 0); }

Page 53: Responsive Navigation Patterns - Respond 2014

Set a transition on the elements we’ll move .navbar { position: fixed; bottom: 0; right: 0; top: 0; width: 66%; padding-top: 3em; transform: translate(100%, 0); } !.navbar, .content, .brand { transition: transform ease-in 300ms; }

Page 54: Responsive Navigation Patterns - Respond 2014

Move the menu and content on toggle .navbar { position: fixed; bottom: 0; right: 0; top: 0; width: 66%; padding-top: 3em; transform: translate(100%, 0); } !.navbar, .content, .brand { transition: transform ease-in 300ms; } .content, .button-toggle.is-on ~ .navbar { transform: translate(0, 0); } .button-toggle.is-on ~ .brand, .button-toggle.is-on ~ .content { transform: translate(-66%, 0); }

Page 55: Responsive Navigation Patterns - Respond 2014

Scaling up to larger screens

Page 56: Responsive Navigation Patterns - Respond 2014

@media screen and (min-width: 40em) { .button-toggle { display: none; } .brand { float: left; width: 15%; } .navbar { position: relative; width: 85%; padding-top: 0; float: left; } .navbar--items li { display: inline-block; padding: 0 1.5%; }

Re-align things like with do nothing !

Page 57: Responsive Navigation Patterns - Respond 2014

! .navbar, .brand, .button-toggle.is-on ~ .brand, .button-toggle.is-on ~ .content { transform: translate3d(0, 0, 0); } }

Ensure the menu is always visible !

Page 58: Responsive Navigation Patterns - Respond 2014

Putting it all together !

Page 59: Responsive Navigation Patterns - Respond 2014

Dealing with larger nav

Page 60: Responsive Navigation Patterns - Respond 2014

Extending the toggle

Page 61: Responsive Navigation Patterns - Respond 2014

Avoid the sub navigation

Page 62: Responsive Navigation Patterns - Respond 2014

Things to bear in mind

Page 63: Responsive Navigation Patterns - Respond 2014

Make navigation items a decent size

Page 64: Responsive Navigation Patterns - Respond 2014

Make navigation items a decent size

Page 65: Responsive Navigation Patterns - Respond 2014

Use this

Page 66: Responsive Navigation Patterns - Respond 2014

Use the devices you are targeting

Page 67: Responsive Navigation Patterns - Respond 2014

Where can people reach

Page 68: Responsive Navigation Patterns - Respond 2014

Resources All the code used in this presentation

github.com/dp-lewis/respond !

Heaps of info about RWD bradfrost.github.io/this-is-responsive

!

Easy to reach places on devices lukew.com/ff/entry.asp?1649

!

Standardising the Icon bit.ly/standardise-icon

Page 69: Responsive Navigation Patterns - Respond 2014

Thank you @dp_lewis