Full screen mobile menu
Description: To compensate for the limited
screen space offered on mobile devices, this mobile-first navigation menu
creates a slide in menu that takes up the entire screen when expanded. Its
content can be defined either as an inline <nav>
element, or inside
an external file and fetched via Ajax. Swiping/ mouse dragging is supported
inside the content to scroll it upwards/downwards should the content exceed the
height of the screen's viewport.
All of the menu's style is defined inside the external stylesheet, including the transition time.
Demo (Toggle menu using button below).
Step 1: Add the below code to the HEAD section of your page:
This script uses the following external files. Download them below (right click, and select "Save As"):
- fullscreenmenu.css
- fullscreenmenu.js
- menucontent.htm (external menu file)
IMPORTANT: Your page should carry the META tag <meta name="viewport"
content="width=device-width">
in the HEAD section of your page to ensure
the best mobile experience with this menu.
This
META tag instructs mobile browsers not to zoom out when rendering the
webpage by default, which can lead to the menu appearing too small to start.
Step 2: Add the below sample HTML button code anywhere on your page to toggle the menu:
<a class="animateddrawer"
href="#" onClick="menu1.togglemenu(); return false">
<span></span>
</a>
That's it for installation! See below for customization details.
More Information
Full Screen Menu is initialized by calling new
fullscreenmenu()
in the HEAD section of your page after the DOM has
loaded, It accepts a single option called "source
" that
sets
the source of the menu contents (whether defined inline on the page, or the path
to an external file):
jQuery(function(){ // on DOM load
menu1 = new fullscreenmenu({ // initialize
menu
source: 'menucontent.htm'
})
})
The variable "menu1
" should be an arbitrary but
unique variable name of your choosing to uniquely identify this instance of Full
Screen Menu. This following describes the lone option is more detail, plus the
togglemenu()
method:
Customizing the fancy animated drawer button
The code that you add to your page by default comes with an animated drawer button to toggle the state of the demo menu. The button's markup is as follows:
<a class="animateddrawer"
href="#" onClick="menu1.togglemenu(); return false">
<span></span>
</a>
Notice inside the onClick event handler how it calls
menu1.togglemenu()
, where "menu1
" should be the variable
name assigned to this instance of Full Screen Menu inside the initialization
code. The button markup should also carry a class of "animateddrawer
",
which does two things:
-
Styles the button as an animated drawer icon inside fullscreenmenu.css (see bottom half of style sheet).
-
Script adds a CSS class of "
open
" to buttons carrying this class when the menu is open, and removes the "open
" class when the menu is closed.
If you study
fullscreenmenu.css, you'll see that the
button by default is positioned relative (so it can be placed anywhere on the
page), though when the menu is open, that changes to a position of "fixed
"
and at the upper right corner of the page (so it's always in view inside the
menu). If you wish the button to be positioned in the upper right corner by
default, change the default position from "relative
" to "absolute
"
or "
". with explicit "top
" and "left
"
properties to boot.