This page is under construction. An updated version will be available soon. |
MMenu (MMenu: short for mobile menu) is a JavaScript plugin for creating app look-alike off-canvas menus. It turns a basic HTML menu structure (with <nav>
, <ul>
, <li>
and <a>
or <span>
elements) into a fully functional off-canvas menu with sliding submenus.
The mmenu.js plugin knows its way around a bit more complex HTML structures as well, so you probably don’t need to change any markup if your migrating from another script or plugin.
For J1 Theme the free to use version MMEnu Light is used. |
Getting started
This documentation page assumes you have some knowledge of HTML, CSS and JavaScript. If you are totally new to frontend development, it might not be the best idea to jump right into a framework as your first step - grasp the basics then come back!
If you’re new to using the mmenu light plugin, please grab a copy of the mmenu light plugin and try the tutorial. |
After the plugin is invoked, there are two add-ons available for the menu: navigation
and offcanvas
.
navigation()
-
Creates the navigation with a fixed navbar and sliding submenus from
<nav />
,<ul />
,<li />
and<a />
(or<span />
) elements. offcanvas()
-
Creates an off-canvas drawer. This drawer can be populated with any kind of content.
Both add-ons navigation and offcanvas have their own set of options, CSS variables and API methods. |
Options
The mmenu light plugin and both the navigation
and offcanvas
add-ons provide a set of options for customizing your menu. The default values can be overridden by passing new values to the method.
<script>
document.addEventListener(
"DOMContentLoaded", () => {
const menu = new MmenuLight(
document.querySelector( "#my-menu" ),
"(max-width: 600px)"
);
const navigator = menu.navigation({
// options
});
const drawer = menu.offcanvas({
// options
});
}
);
</script>
Mmenu Plugin
Method | Datatype | Default | Description |
---|---|---|---|
| HTMLElement |
| The HTML element you want to turn in an off-canvas menu. .Example
|
| String |
| MediaQuery for when the menu should be enabled. |
Navigation add-on
Method | Datatype | Default | Description |
---|---|---|---|
| String |
| Classname to use for finding the selected
|
| Boolean |
| Wether or not to use sliding submenus (forced to be |
| String |
| The title above the main panel. For subpanels the text in its parent menu item is used. |
| String |
| Color scheme to use. Possible values: |
Offcanvas add-on
Method | Datatype | Default | Description |
---|---|---|---|
| String |
| The position for the menu. Possible values:
|
Styling (CSS)
It’s pretty easy change the styling for the mmenu light plugin, just override some of the CSS values and variables.
.mm {
background: #ffe;
color: #330;
--mm-spn-item-height: 46px;
--mm-ocd-max-width: 500px;
}
Navigation add-on
It’s pretty easy change the styling for the mmenu light plugin, just override some of the CSS values and variables.
Variables | Datatype | Default | Description |
---|---|---|---|
| Color |
| Background-color for the menu. |
| Color |
| Color for the text and borders in the menu. |
Variables | Datatype | Default | Description |
---|---|---|---|
| CSS value |
| Height for menu items. |
| CSS value |
| Indent for menu items. |
| CSS value |
| Line-height for text in the menu.
|
Offcanvas add-on
It’s pretty easy change the styling for the mmenu light plugin, just override some of the CSS values and variables.
Variables | Datatype | Default | Description |
---|---|---|---|
| CSS value |
| Position relative to the top of the page. |
| CSS value |
| Position relative to the bottom of the page. |
Variables | Datatype | Default | Description |
---|---|---|---|
| CSS value |
| Width for the menu. |
| CSS value |
| Minimal width for the menu. |
| CSS value |
| Maximum width for the menu.
|
API
After invoking the add-ons, an API is available for each add-on. With this API, you can invoke the add-on methods to control the plugin manually.
<script>
document.addEventListener(
"DOMContentLoaded", () => {
const menu = new MmenuLight(
document.querySelector( "#my-menu" )
);
const navigator = menu.navigation();
const drawer = menu.offcanvas();
navigator.openPanel(
document.querySelector( "#my-ul" );
);
document.querySelector( 'a[href="#my-menu"]' )
.addEventListener( 'click', ( evnt ) => {
evnt.preventDefault();
drawer.open();
});
}
);
</script>
Navigation add-on
openPanel
Invoke this method to open a panel in the menu.
Arguments | Datatype | Default | Description |
---|---|---|---|
| HTMLElement |
| Panel (UL) to open. |
Off-Canvas add-on
Creates an off-canvas drawer. This drawer can be populated with any kind of content.
Method | Datatype | Default | Description |
---|---|---|---|
| NA | NA | Invoke this method to open the menu. Example
|
| NA | NA | Invoke this method to close the menu. Example
|