Reputation: 3885
I did my own delay function for my dropdown menu. Since I'm kind of new to JavaScript I would like to know if this can be done in a better way?
var $hasSubpages = $("#divContainer .classForPagesWithSubpages");
function theFunction(){$('#theID').find('.classForChild').slideDown(400);}
var timer;
$hasSubpages.hover(
function (){
timer = setTimeout(theFunction, 500);
$(this).attr('id','theID');
},
function(){
clearTimeout(timer);
$(this).attr('id','').find('.classForChild').slideUp(400);
}
);
Upvotes: 0
Views: 1027
Reputation: 42818
Use the delay() function
$('#test').slideDown(500).delay(3000).slideUp(500);
This will cause the element to slidedown wait 3 seconds then slide back up
Upvotes: 0
Reputation: 30187
there is already a beautiful plugin with the name hoverIntent already developed for that.
http://plugins.jquery.com/project/hoverIntent
If you need any help understanding how it works i can tell you. Otherwise its very easy to work with.
Upvotes: 1