MMenu Open on Load with close
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/jQuery.mmenu/5.3.1/js/addons/jquery.mmenu.fixedelements.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jQuery.mmenu/5.3.1/js/jquery.mmenu.min.js"></script>
<div id="page">
<div class="header Fixed">
<a href="#menu" class="btn btn-default"></a>
Demo
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-6" aria-expanded="false">
<span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span>
</button> <a class="navbar-brand" href="#">Brand</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-6">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
</ul>
</div>
</div>
</nav>
</div>
<div class="content" id="content">
<div id="intro">
<p><strong>This is a demo.</strong><br />
Click the menu icon to open the menu.</p>
<p>The links in the menu link to a section on the same page, some small javascript makes the page scroll smoothly.</p>
</div>
<div id="first">
<p><strong>This is the first section.</strong><br />
Notice how the fixed header and footer slide out along with the page.</p>
<p><a href="#menu">Open the menu.</a></p>
</div>
<div id="second">
<p><strong>This is the second section.</strong><br />
You can also drag the page to the right to open the menu.</p>
<p><a href="#menu">Open the menu.</a></p>
</div>
<div id="third">
<p><strong>This is the third section.</strong><br />
<a...
CSS
@import url('https://cdnjs.cloudflare.com/ajax/libs/jQuery.mmenu/5.3.1/css/extensions/jquery.mmenu.widescreen.css') screen and (min-width: 900px);
@import url('https://cdnjs.cloudflare.com/ajax/libs/jQuery.mmenu/5.3.1/css/jquery.mmenu.css');
html, body
{
padding: 0;
margin: 0;
}
body
{
background-color: #fff;
font-family: Arial, Helvetica, Verdana;
font-size: 14px;
line-height: 22px;
color: #666;
position: relative;
-webkit-text-size-adjust: none;
}
body *
{
text-shadow: none;
}
h1, h2, h3, h4, h5, h6
{
line-height: 1;
font-weight: bold;
margin: 20px 0 10px 0;
}
h1, h2, h3
{
font-size: 18px;
}
h4, h5, h6
{
font-size: 16px;
}
p
{
margin: 0 0 10px 0;
}
a, a:link, a:active, a:visited, a:hover
{
color: inherit;
text-decoration: underline;
}
nav:not(.mm-menu)
{
display: none;
}
.header,
.content,
{
text-align: center;
}
.header
{
background: #777;
font-size: 16px;
font-weight: bold;
color: #fff;
line-height: 40px;
-moz-box-sizing: border-box;
box-sizing: border-box;
width: 100%;
height: 40px;
padding: 0 50px;
}
.header.fixed
{
position: fixed;
top: 0;
left: 0;
}
.header a
{
background: center center no-repeat transparent;
background-image: url( data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAAZCAYAAADE6YVjAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAADhJREFUeNpi/P//PwOtARMDHQBdLGFBYtMq3BiHT3DRPU4YR4NrNAmPJuHRJDyahEeT8Ii3BCDAAF0WBj5Er5idAAAAAElFTkSuQmCC );
display: block;
width: 40px;
height: 40px;
position: absolute;
top: 0;
left: 10px;
}
.content
{
padding: 150px 50px 50px 50px;
}
#intro,
#first,
#second,
#third
{
height: 400px;
}
#intro
{
padding-top: 0;
}
#first,
#second,
#third
{
border-top: 1px solid #ccc;
padding-top: 150px;
}
.header
{
box-sizing: border-box;
width: 100%;
position: fixed;
}
.header
{
top: 0;
}
JavaScript
$(function() {
var $menu = $('nav#menu'),
$html = $('html, body');
$menu.mmenu({
extensions: ["widescreen", "theme-dark"]
});
var $anchor = false;
$menu.find( 'li > a' ).on(
'click',
function( e )
{
$anchor = $(this);
}
);
var api = $menu.data( 'mmenu' );
api.bind( 'closed',
function()
{
if ( $anchor )
{
var href = $anchor.attr( 'href' );
$anchor = false;
if the clicked link is linked to an anchor, scroll the page to that anchor
if ( href.slice( 0, 1 ) == '#' )
{
$html.animate({
scrollTop: $( href ).offset().top
});
}
}
}
);
});