Skip to content

Instantly share code, notes, and snippets.

@jimjeffers
Created February 27, 2009 16:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimjeffers/71548 to your computer and use it in GitHub Desktop.
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.
// 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