Home

Awesome

megamenu-js

Last responsive megamenu you'll ever need

huge thanks to Michele Maietta (https://github.com/doppiam) for all contribution in this project.

Features

Demos

Download and open index.html or:

Live Demo

Live demo is avaliable on codepen megamenu.js demo

To do

Instalation

  1. Copy CSS from style.css or style.less

1.1) megamenu.js uses ionicons, so include their script or edit CSS for your icon-font, svg, img or what ever

  1. Include jquery just before closing body tag </body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
  1. Include megamenu.js below jquery
<script src="js/megamenu.js"></script>
  1. Wrap your menus HTML in megamenu.js wrappers and see the magic :)
<div class="menu-container">
        <div class="menu">
                <ul>
                  <li></li>
                  <li></li>
                  <!-- What ever, basic html menu(lists)! Dont worry megamenu.js will know -->
                </ul>
        </div>
    </div>

Usage and jquery explanation

megamenu.js is 100% class-less. That means that none CSS classes are used for displaying dropdowns. Its made with HTML schematic logic in mind. Because of that does not require custom walkers with wordpress. When jquery triggers for mobile menu, its appending HTML for mobilemenu so there is no need for checkboxes or anything else. The menu is 100% autonomous, and smart.

Why is megamenu.js smart

megamenu.js knows if the dropdowns are too big and then shows them as megamenu. But if there is no need for a megamenu, jquery is triggering a normal, classic dropdown menu. In real world, you maybe wont need all of the menus to be a megamenu, but because of a attempt of a complete automation, the menu decides when and when not to show a menu as a megamenu.

Conditions integrated into megamenu.js

Wordpress integration

Since megamenu.js is not using classes for displaying drodowns, wordpress integration is seamless. That means custom walkers are not needed! Wordpress is adding classes to every UL and LI element by default, so first thing you need to do is clear menu from classes.

1) In your functions.php add these lines (taken from HTML5blank by @toddmotto)

// Remove the <div> surrounding the dynamic navigation to cleanup markup
function my_wp_nav_menu_args($args = '')
{
    $args['container'] = false;
    return $args;
}
// Remove Injected classes, ID's and Page ID's from Navigation <li> items
function my_css_attributes_filter($var)
{
    return is_array($var) ? array() : '';
}

add_filter('wp_nav_menu_args', 'my_wp_nav_menu_args'); // Remove surrounding <div> from WP Navigation
add_filter('nav_menu_css_class', 'my_css_attributes_filter', 100, 1); // Remove Navigation <li> injected classes
add_filter('nav_menu_item_id', 'my_css_attributes_filter', 100, 1); // Remove Navigation <li> injected ID
add_filter('page_css_class', 'my_css_attributes_filter', 100, 1); // Remove Navigation <li> Page ID's

That clears the menu from everything wordpress has added and from this point the menu is like you are doing a static version.

2) Then simply wrap the wordpress menu with megamenu.js wrappers!

<div class="menu-container">
    <div class="menu">
      <?php wp_nav_menu(); ?>
    </div>
</div>

Made with (thanks)