Created
February 27, 2009 16:23
-
-
Save jimjeffers/71548 to your computer and use it in GitHub Desktop.
Give any element a class of '.sub_navigation' and bam you have a hover show/hide with timeouts for better usability. Requires jQuery.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Handle any drop down navigation systems. | |
$(document).ready(function(){ | |
$('.sub_navigation').each(function() { | |
var menu = $(this); | |
menu.hide(); | |
var parent = $(menu.parent().get(0)); | |
var timeout = false; | |
parent.hover(function(){ | |
if(!timeout && !menu.is(':visible')) { | |
timeout = setTimeout(function(){ | |
menu.show(); | |
parent.addClass('active'); | |
timeout = false; | |
}, 350); | |
} else { | |
if(timeout) { | |
clearTimeout(timeout); | |
} | |
timeout = false; | |
} | |
}, | |
function(){ | |
if(!timeout && menu.is(':visible')) { | |
timeout = setTimeout(function(){ | |
menu.hide(); | |
parent.removeClass('active'); | |
timeout = false; | |
}, 350); | |
} else { | |
if(timeout) { | |
clearTimeout(timeout); | |
} | |
timeout = false; | |
} | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment