Simple jQuery Mobile Menu

A mobile friendly jQuery and CSS3 menu that’s simple, image-free, and pretty.

View jQuery Mobile Menu System Demo

Screenshot_2013-03-16-23-29-24

There are a number of great scrips and plugins out there for adding fancy mobile menus, but they normally take awhile to configure and perfect. For the do-it-yourself type, this is a light and simple jQuery mobile menu system that will get you up and running in no time and within budget.

#1 Load jQuery

If you are using WordPress, copy this into your theme’s functions.php file. If you already have the jQuery library hard coded into your theme’s header or footer, remove it and use this. WP_Enqueue_Script will make sure that jQuery is loaded (at wp_head) and that only one copy of jQuery gets loaded.

If you want to load jQuery in the footer (wp_footer), add an extra TRUE parameter to the end of the function.

#2 Add your mobile menu HTML

I’ve included two menu toggle (open/close) styles. The navicon (3 bar button) at the top right of the demo is becoming the mobile standard icon for menu toggling. If you are using Chrome, look to the top right of your browser and you will see it. The other menu toggle button to the left spells out what it is for. This style can be of assistance to those who are new to tablet/smartphone browsing and old people.

You could also turn the entire black bar into a menu toggle bar by adding class=”mtoggle” to the nav tag.

This jQuery mobile menu was designed to be flush with the top of the screen.

If you are using WordPress, use your WordPress theme’s menu code in place of the unordered list. Something like this:

#3 Add your jQuery toggle code

Make sure the jQuery library loads before this script:

 #4 Add your responsive CSS:

If you add position:fixed styling rule to the nav tag css, the menu bar will stay fixed at the top of the screen as the user scroll down your page. It’s convienent having the menu bar always available, but it takes away from screen real estate. If you do make the menu bar fixed, make sure you add enough top padding to the first item in the page to be sure it doesn’t try to go behind the bar and dissapear.

You will want to hide this mobile menu on large screen devices and use your primary menu system instead. Use the reponsive CSS below to achive this. For your large screen CSS, set nav#mobile to display:none. In your mobile CSS, set nav#primary-navigation-id to display:none.

View jQuery Mobile Menu System Demo