> Slide-in menu

slidein-menu

Sometimes the screen of mobile devices is too small to fit all the controls, menus and options of your application. One solution is to create a slide in menu that the user can pull to access additional functions.


Project info

Last code update: 2010.05.28 – v0.1 beta 1
Device compatibility: iPhone/Ipod touch >=2.0, Android >1.6, iPad.
QR Code opens demo page. (On Android you may need to refresh the page once loaded, I’m looking into this issue with QR links).

Support development

If this script saved your day or you wish to support future developments you may consider sending some funds via PayPal.


Overview

Sometimes the screen of mobile devices is too small to fit all the controls, menus and options of your application. One solution is to create a slide in menu that the user can pull to access additional functions.

The menu is opened both by tapping and pulling the handle.

This widget is ridiculously simple, all it does is to slide in a hidden div on user’s request. Please note that the script is just a draft, I’ll keep developing it if there’s enough interest (see below).

How to use

Initialize the slide in menu on DOMContentLoaded:

menu = new slideInMenu('slidedownmenu');

slidedownmenu is the ID of the element to be slided.

The slider has to be absolutely positioned and the top:

#slidedownmenu {
  position:absolute;
  width:100%;
  height:115px;
  top:-115px;
  left:0;
  z-index:999;
}

The the example I set the top property to -115px so the menu is hidden while the page loads, but it’s not mandatory. The slideInMenu() function takes care of placing the div in the right position.

The handle is positioned to the bottom of the sliding layer. To make it stick out the initially closed menu you just need to set the bottom property equal to the negative value of the handle height:

#slidedownmenu .handle {
  -webkit-user-select:none;   /* user can't select */
  position:absolute;
  width:100%;
  height:20px;
  bottom:-20px;
  left:0;
}

Look at the source code of the online demo for details.

Syntax

The function accepts two parameters at startup:

slideInMenu(string ID, bool openAtStartup);

ID is the menu identifier. If you set openAtStartup to TRUE the menu will be in opened when initialized.

You can also open, close and toggle the menu programmatically.

var menu = new slideInMenu('slidedownmenu', true); // Initialize the menu and open it right away

menu.open();	// Open the menu

menu.close();	// Close the menu

menu.toggle();	// Toggle the menu open/close state

Future developments

  • Add Android compatibility
  • Programmatically open/close the menu
  • Should be possible to place the menu anywhere (ie: slide down/up/left/right)

Revisions history

v0.1 beta 1, 2010.05.28 – Added Android compatibility
v0.1 alpha 1, 2010.05.25 – Initial release

/Share the joy

/Reactions

    • Author: Joel
    • Posted on: 2012/02/06
    • At: 21:58

    Great plugin, this is really useful. Any suggestions on how to integrate this with jquery mobile?

    Reply
    • Author: steven hyle
    • Posted on: 2012/02/07
    • At: 19:23

    Hi,

    I’m trying to make the bar stay horizontal, however, when “open” it slides left to right.

    I like the bar being at the top with a width of 100%, however, I went the menu to fly in from left to right with a height of 100%.

    Can you please help?

    Reply
  • cool – love your work! simple, solid and useful.

    Reply
  • Hello, i feel that i saw you visited my weblog thus i came to return the desire?.I am trying to in finding issues to improve my web site!I guess its adequate to use some of your concepts!!

    Reply
  • You may want to take this off the Project State: Active, since there hasn’t been an update in almost 2 years :)

    That said, have you thought about modifying this to handle a 2-row menu (the 2nd row being the “dropdown” for the first) ?

    Tom

    Reply
    • Author: tom bee
    • Posted on: 2012/02/19
    • At: 06:30

    Is there anyway to change this to make it a slidein-menu from the bottom?

    Reply
    • Author: Francisco
    • Posted on: 2012/03/06
    • At: 21:39

    Really awesome, it works fine on Chrome and Safari, too bad it ONLY works there… doesn’t work on IE9, Opera or Firefox. :(

    Good job though.

    Reply
      • Author: Jesse
      • Posted on: 2012/03/13
      • At: 02:44

      Meanwhile, this is intended for MOBILE use. Just saying.

      Reply
    • Author: odnel
    • Posted on: 2012/03/26
    • At: 02:19

    This is really awesome, but i have a problem with a android where the website won’t scroll on the mobile page due to the “loaded” function in the file. I take that out and it works fine but obviously the menu bar doesn’t move. How can I fix this, thanks in advance!

    Reply
    • Author: De
    • Posted on: 2012/04/11
    • At: 15:28

    Nice! Works properly on blackberry playbook..

    Reply
    • Author: Hmm..
    • Posted on: 2012/05/06
    • At: 07:55

    It dosen’t work quite well in a web application on iOS 5. It, didn’t worked that well.

    When I tried to pull down the menu (full screen web app), well, on iOS 5, the Notification Center slides down first.

    Well, there should be a way to move the menu to the bottom, instead.

    Reply
    • Author: Rayken
    • Posted on: 2012/05/07
    • At: 13:47

    Great script!

    I only have one problem with it though, it’s when you go from portrait to landscape or vise versa. Once you’ve loaded the page in portrait, open the menu and go landscape the elements inside are misplaced as it seems the top/left values are wrongly interpreted. Closing the menu will simply make it go outside the view area and is no longer accessible unless you reload the page. Once you do, however, switching from landscape to portrait works as intended. I believe some sort of rotation detection needs to be added to deal with the element positions!

    Any input on this would be highly appreciated as it isn’t very user friendly having to reload the page to bring back the menu / make it work as intended.

    Best regards,
    Rayken

    Reply

/Leave a reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>