I am currently trying to make a menu with a submenu. Here is what I want to do.
When hovering a link (#mylink), I want to display a div (lets call it "#submenu") right below it. Leave this link on the mouse; you want to execute the function in 5 seconds.
In this interval, 5 seconds, if I find my div (#submenu), I want clearTimeout. So this div will not fade after 5 seconds.
Here is my code:
$(document).ready(function()
{
$("#mylink").hover(
function ()
{
$('#submenu').show();
},
function()
{
var timer = setTimeout(function(){$('#submenu').hide();}, 5000);
}
);
$("#submenu").hover(
function ()
{
clearTimeout(timer);
},
function()
{
$('#submenu').show();
}
);
}
source
share