4

I previously asked about developing an iOS based side-swipe menu. Now that sideswipe menus have become a standard user interface component, they are beginning to transfer over to the mobile web. Medium is one of the first I've seen to successfully pull of this type of menu on the mobile web (pictured below). My question is: what is the most effective way of implementing something like this on the web?

enter image description here

Community
  • 1
  • 1
Nick ONeill
  • 7,341
  • 10
  • 47
  • 61

3 Answers3

6

I hate to be that person to just drop a link but there's a very good write up about this very topic here: http://coding.smashingmagazine.com/2013/01/15/off-canvas-navigation-for-responsive-website/

It covers a web based menu with animation and it covers best practices for animating the menu smoothly. The article is pretty detailed making it difficult to summarize its content. Hopefully it will help.

hradac
  • 2,431
  • 1
  • 19
  • 21
1

If you aren't against jQuery Mobile, this can be very simple:

http://view.jquerymobile.com/1.3.0/docs/examples/panels/panel-swipe-open.php

danielrsmith
  • 4,050
  • 3
  • 26
  • 32
0

Here is how I would approach it (of course this is just an example of the animation, I've left out everything else):

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style>
body, html {margin:0;padding:0;}
#iphone {width:320px; height:480px; overflow:hidden; border:solid black thin; display:block;}
#menu {position:fixed; top:1;left:-250px; width:250px; height:480px; display:block; background-color:#868686;}
#content {position:absolute; width:320px; background-color:#cccccc; display:block;}
</style>
</head>

<body>
<div id="iphone">
<div id="menu">I am a menu <button onclick="hideMenu();">close</button></div>
<div id="content">I am the site content, click this <button onclick="showMenu();">menu</button></div>
</div>
</body>
<script>
var m=document.getElementById('menu');
var c=document.getElementById('content');
function showMenu(){
    if(m.offsetLeft<0){
        m.style.left=(m.offsetLeft+10)+'px';
        c.style.left=(c.offsetLeft+10)+'px';
        setTimeout(showMenu,16)
    }

}
function hideMenu(){
    if(m.offsetLeft>-250){
        m.style.left=(m.offsetLeft-10)+'px';
        c.style.left=(c.offsetLeft-10)+'px';
        setTimeout(hideMenu,16)
    }

}
</script>
</html>
Robot Woods
  • 5,677
  • 2
  • 21
  • 30
  • One downside of this approach is the use of absolute positioning. Is it possible to shift an element's position without it being fixed or absolute? – Nick ONeill Feb 22 '13 at 17:53