Home | Projects | Tutorials | Articles | live chat | Submit Project | Big Vote
 
Ajax Projects
.NET Frameworks
Java Frameworks
PHP Frameworks
Ruby Frameworks
Other Frameworks
Cool AJAX sites
Ajax Resources
Ajax Tools
JavaScript frameworks

 Home /  Tutorials / Flyout Menu Tutorials

Flyout Menu Tutorials





Fly-out menu is a tool designed to help you access your favorite sections and stories,and allow you to display multiple menu items without cluttering the page. Here you can learn how to Create a simple fly-out menu:

Read The Full Tutorial.
































Fly-out menu is a tool designed to help you access your favorite sections and stories,and allow you to display multiple menu items without cluttering the page.


Here you can learn how to Create a simple fly-out menu:

var $menu = $('ul.menu_options');

//hide all of the menus
$menu.hide();

$('a.trigger').each(function(index) {
 $(this).click(function() {
  //identify the clostest menu
  $nextMenu = $(this).next($menu);
  if ($nextMenu.is(":visible")) {
   $nextMenu.fadeOut('fast').css('z-index', '50');
  } else {
   $menu.hide(); //close all other open menus
   $nextMenu.show().css('z-index', '500'); //z-index for good measure
  }

  return false;
 });
});

 

but it have a problem that the menu hangs around until you click the trigger again to close it.

Here is the ideal behavior:

    * If you trigger the menu and do nothing, it will go away after n seconds.
    * If you trigger the menu and mouseover it, it will stay there.
    * When you mouse leaves the menu, it will go away after n seconds.

var $menu = $('ul.menu_options');
var $open = $('a.trigger');

//create an emtpy object to keep track of the timeouts
var menuTimeouts = {};

//hide all of the menus
$menu.hide();

$open.each(function(index) {
 $(this).click(function() {
  //identify the clostest menu
  $nextMenu = $(this).next($menu);
  if ($nextMenu.is(":visible")) {
   $nextMenu.fadeOut('fast').css('z-index', '50');

                        //clear the active setTimout
   if (menuTimeouts[$id]) {
    clearTimeout(menuTimeouts[$nextMenu.attr('id')]);
           menuTimeouts[$nextMenu.attr('id')] = undefined;
                  }
  } else {
   $menu.hide(); //close all other open menus
   $nextMenu.show().css('z-index', '500'); //z-index for good measure

   //start a unique setTimeout for this menu
   menuTimeouts[$nextMenu.attr('id')] = setTimeout(function () {
    //fade the menu out after 2 seconds
    $nextMenu.fadeOut('slow');
   }, 2000)
  }

  return false;
 });
});

$menu.find('li').mouseenter(function (event) {
 //store the ID of this trigger's closest menu
 var $id = $(this).parents('ul').attr('id');

 //cancel the timeOut when the mouse is over the menu
 if (menuTimeouts[$id]) {
  clearTimeout(menuTimeouts[$id]);
  menuTimeouts[$id] = undefined;
 }
}).mouseleave(function () {
 var $this = $(this).parents('ul');

 //start another time when the mouse leaves the menu
 menuTimeouts[$this.attr('id')] = setTimeout(function () {
  $this.fadeOut('slow');
 }, 2000);
});

AddThis Social Bookmark Button
Top Projects
MSN Web Messenger
MessengerFX
ebuddy
e-messenger
ILoveIM
You Tube
AJAX file upload
KoolIM.com
Meebo
Ajax.NET Professional
Tutorials
Reading ID3 tags with JavaScript
Handling Session timeout & other server http errors in AJAX
Ajax Dynamic Tab Panes
How to add Google Maps to your website?
Refresh Content in UpdatePanel using Asp.net Ajax Timer Control
Chrome Extension Process Model Design Doc
Submit multiple forms with jQuery and Ajax
AJAX and PHP Building Responsive Web Applications
Dealing with Long Running Processes in ASP.NET
ASP.NET Ajax Chat Application