Created
July 19, 2011 19:30
-
-
Save s-aska/1093491 to your computer and use it in GitHub Desktop.
jQuery hover delay
This file contains 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
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