Skip to content

Instantly share code, notes, and snippets.

@s-aska
Created July 19, 2011 19:30
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 s-aska/1093491 to your computer and use it in GitHub Desktop.
Save s-aska/1093491 to your computer and use it in GitHub Desktop.
jQuery hover delay
function delayHover(element, over, out, delay) {
var timer;
$(element).hover(function(){
if (timer) {
clearTimeout(timer);
timer = null;
} else {
over.apply(this, arguments);
}
}, function(){
var that = this,
args = $.makeArray(arguments);
timer = setTimeout(function(){
out.apply(that, args);
timer = null;
}, delay);
});
}
// example
$('.pulldown').each(function(){
var menu = $(this).find('> .pulldown-menu');
delayHover(this, function(){
menu.slideDown();
}, function(){
menu.slideUp();
}, 500);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment