Coder Social home page Coder Social logo

megamenu's Introduction

megamenu-js

responsive megamenu

Michele Maietta (https://github.com/doppiam)

Features

  • Cross-browser compatibility
  • No classes! (for dropdowns or lists)
  • Smart - knows when to show megamenu, and when to show a normal dropdown
  • 100% responsive, works on all devices
  • Seamless wordpress integration
  • Super fast
  • Uses jquery animations (IE8 compatible)
  • Easy to use
  • Written in LESS (easy to abuse)
  • Uses ionicons
  • Super small
  • Free to use and abuse (MIT licence)

Demos

Download and open index.html or:

Live Demo

Live demo is avaliable on codepen megamenu.js demo

To do

  • rewrite plugin in vanilla JS
  • make CSS only animation version, for no < IE11 support

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

  • Classic dropdown menu, when there is no need for a megamenu (dropdowns LI element does not have another child)
  • Megamenu, when there are many levels of dropdowns (dropdowns LI element has another child and so on)
  • Megamenu with empty sub, mixed condition of two before (some LI elements have another child, some dont)

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)

megamenu's People

Contributors

bullend avatar

Stargazers

 avatar

Watchers

 avatar

megamenu's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.