McMenu: Mobile-Friendly Dropdown Menu

Templates: 1 2 3 4 5

Thanks for using Menucool McMenu

The download package contains the source code and all five templates.
Please confirm.
Confirm

Features

HTML

CSS

JavaScript

Open mcmenu.js from the downloaded files and adjust the options to fit your needs:

var mcmenuOptions =
{
        menuId: "mcmenu",

        open: "onmouseover",  //or "onclick"

        delay: 90,

        mobileBreakpoint: 500,

        breakpointMode: 1,

        multirow: null,

        mobileDropdownDirection: 1,

        linkIdToMenuHtml: null,

        topItemAnimation: "1, 0.5, ease"
};
var mcmenu = new McMenu(mcmenuOptions);
......

Dynamic Menu Creation

McMenu initializes when the page loads. If the menu markup is added later, initialize ddmenu using one of two methods:

The menu id specified in the HTML markup:<div id="mcmenu">...</div>

Ways to open sub-menu dropdown:

either "onmouseover" or "onclick".

The menu will turn to mobile mode if the width is or less than this breakpoint.

Please refer to next property, breakpointMode, to see what the width means.

Value:

Specify what the mobileBreakpoint width refers to.

It has three possible values: 1, 2, or 3.

  • 1: Viewport width (browser window width).
    Equivalent to the CSS media queries @media (max-width: ?px).
  • 2: Device width.
    Equivalent to the CSS media queries @media (max-device-width: ?px).
  • 3: Width of the menu's containing element, provided it is not fixed.

Option 1 is the most commonly used. Option 3 is demonstrated in the example on this page.

Note: Be sure to have the following code in the head section of your page:<meta name="viewport" content="width=device-width, initial-scale=1.0" /> Otherwise, the script may not correctly detect the browser width on mobile devices.

You can insert a breakpoint between desktop and mobile phone.

Its value can be:

  • null: There is no breakpoint for tablets.
  • "breakpoint:columnNumber": For example, "1000:3" means when the Width* is or smaller than 1000px, the top menu will become multiple rows with 3 items in each row.

    *The Width mentioned above: Please refer to the previous property breakpointMode.

Configures the sliding direction when sub-menu(dropdown) is opening in mobile mode. Its value options:

  • 1: Sliding-in from right to left.
  • 2: Sliding-down. Opening a dropdown will not close other opened dropdowns.
  • 3: Sliding-down. Opening a dropdown will also close other opened dropdowns.
linkIdToMenuHtml:  null by default. If you want to store your website menu in a separate file so that you do not need to cut and paste the menu HTML code into every pages, you can assign linkIdToMenuHtml with a link ID and link it to a separate menu code file. Please refer to Manage menu code in one central place for details.

Specifies the animation effect for the top-level links in mobile mode.

Leave this box blank if you don't need animations for the top-level links.

Its value format: Animation order, duration, timing-function

  • Animation order
    • 1: The animation will start from the first link to the last
    • -1: The animation will start from the last link to the first
  • duration: number in seconds
  • Timing-function: possible values such as linear, ease, cubic-bezier(n,n,n,n). For details please refer to animation-timing-function.