Emenu, a jQuery plugin

I suppose since I’ve given up MooTools, I’d get more familiar with jQuery, which I’ve used primarily for work. And what better way to do that than to port one of my Mootools plugins to jQuery! You can find it in the jQuery plugin repository.

I made it more flexible than the original because now you can use whatever effect you want. There are four custom events that I’ve added, and here are the defaults:

$('#containerId').emenu({
  over: function(event, bg){
    bg.stop().fadeTo(400, 0.5);
  },
  out: function(event, bg){
    bg.stop().fadeTo(400, 1);
  },
  show: function(event, ul, li, width, height){
    ul.css('visibility', 'visible').stop(true).fadeTo(200, 1);
  },
  hide: function(event, ul, li){
    ul.stop(true).fadeTo(200, 0, function(){
      ul.css('visibility', 'hidden');
    });
  }
});

There are three ways to add your own. You can overwrite them like above by passing in your own or you can do $.fn.emenu.defaults.[event] = function(){...}. Plus since they are custom events attached to the container, you can also do $("#containerId").bind('emenu.[event]', function(){...}). Keep in mind this won’t overwrite the defaults unless you unbind them first.

The custom events receive a few arguments worth explaining.The events over and out receive the div element that contains non-menu-related content; show and hide receive the item menu moused over/out and its submenu. Additionally, show receives the height of the menu and the width of the submenu if you’ve used auto-calculation.

There’s a demo and additional options listed on the plugin page.

I think I’ll be working on converting my other scripts to jQuery as well so keep an eye out for them!

12 Responses to “Emenu, a jQuery plugin”

  1. SRiley

    When I use emenu, links embedded elsewhere on the page do not work if they are positioned in the area underneath the submenu. To clarify: the submenu has a height of 500 px. Any links within that range (ie, an image link, etc) will not work. Links lower than 500 px from the menu will work. Any way around this? I tried reducing the menu_content height to 10 px, etc. but it didn’t help.

  2. Chris

    SRiley, I’m not quite sure I understand what you mean. Do you have a test page or screenshot I can look at?

  3. BKim

    Thanks for this very useful plug-in! Is there any way to make the sub-menu have a different width than the heading?

  4. BKim

    If I set autocalc at false, the top menu width is not evenly distributed although the submenu width gets expanded to accommodate the longest li item as I want.

    $(document).ready(function(){
    $(‘#menu1′).emenu({
    autocalc: false,
    });
    });

    How could I keep the top menu width at auto and at the same time make the sub-menu(ul li ul li ul li a) have not the same width as the top menu so that a log list item won’t get wrapped in multiple lines? Thanks!!!

  5. TomTom

    Hi Chris. First of all; Love your menu. Very nice designed and userfreiendly. However, I am trying to configure it to make something similar. How would uou go about to have the 3,4,5… levels appear beside each other? Is there any easy fix. This is what I am trying to accomplish: http://hibaweb.h-k.no/example.gif. Here is an example of my menu so far: http://hibaweb.h-k.no/temp.html

  6. Chris

    BKim & TomTom,

    If you want to modify default behaviour, your best bet is to start with the custom events outlined above.

  7. Toshi

    Thank you for offering a good plug-in.
    What is the kind of the license of emenu?

  8. Chris

    Toshi, MIT license. You are free to use it as you like.

  1. chromasynthetic » Blog Archive » Flash Without Flash: Elegant Menu Fly-out
    Pingback on February 1st, 2009 at 3:05 pm
  2. Best jQuery Menu Plugins- Free & Easy | guidesigner.com
    Pingback on April 3rd, 2009 at 3:58 am
  3. Great Jquery Menu plugins | psd2css
    Pingback on August 19th, 2009 at 10:48 am
  4. 36 Latest and Fresh jQuery Plugins Write Less Do More Episode - 3
    Pingback on August 5th, 2011 at 7:51 am