Lightweight Mobile App Navigation System – mmenu-light

Category: Javascript , Menu & Navigation | September 15, 2019
Author: FrDH
Views Total: 38
Official Page: Go to website
Last Update: September 15, 2019
License: CC-BY-4.0

Preview:

Lightweight Mobile App Navigation System – mmenu-light

Description:

mmenu-light is a light version of the mmenu plugin that makes it easier to create off-canvas hamburger navigation just like the native mobile app.

No dependencies, no extensions, no addons. Easy to implement a pretty clean and mobile-friendly navigation system in your web app just in a minute.

How to use it:

Import the stylesheet mmenu-light.css and JavaScript mmenu-light.js into the HTML.

<link rel="stylesheet" href="./dist/mmenu-light.css" />
<script src="./dist/mmenu-light.js"></script>

Create an anchor link for the hamburger toggle button.

<a href="#menu"><span></span></a>

Create a multi-level off-canvas menu from nested HTML lists.

<nav id="menu">
  <ul>
    <li class="Selected"><a href="#">Home</a></li>
    <li><span>About us</span>
      <ul>
        <li><a href="#about/history">History</a></li>
        <li><span>The team</span>
          <ul>
            <li><a href="#about/team/management">Management</a></li>
            <li><a href="#about/team/sales">Sales</a></li>
            <li><a href="#about/team/development">Development</a></li>
          </ul>
        </li>
        <li><a href="#about/address">Our address</a></li>
      </ul>
    </li>
    <li><a href="#contact">Contact</a></li>
  </ul>
</nav>

Initialize the off-canvas navigation. Possible options:

  • title: menu title
  • theme: ‘light’ or ‘dark’
  • selected: CSS class for ‘Selected’ item
const menu = new MmenuLight( document.querySelector( '#menu' ), {
      // title: 'Menu',
      // theme: 'light',
      // selected: 'Selected'
});

Enable/disable the off-canvas navigation on specific screens.

// enable the navigation on all devices
menu.enable( 'all' ); 

menu.disable(); 

// enable the navigation on small devices
menu.enable( "(max-width: 640px)" )

Activate the off-canvas navigation. Possible options:

  • position: ‘left’ or ‘right’
  • move: push the content to the other side
  • blockPage: true, false, or ‘modal’
menu.offcanvas({
  // position: 'left',// [| 'right']
  // move: true,// [| false]
  // blockPage: true,// [| false | 'modal']
});

Enable the hamburger button to toggle the off-canvas navigation.

document.querySelector( 'a[href="#menu"]' )
.addEventListener( 'click', ( evnt ) => {
  menu.open();

  //  Don't forget to "preventDefault" and to "stopPropagation".
  evnt.preventDefault();
  evnt.stopPropagation();
});

Changelog:

v2.3.1 (09/15/2019)

  • Fixed for IE11.

v2.3.0 (09/14/2019)

  • vertical submenus + IE11 support

You Might Be Interested In:


Leave a Reply