jquery hover and setTimeout / clearTimeOut

后端 未结 4 1929
北海茫月
北海茫月 2020-12-29 16:56

I\'m currently trying to do a menu with submenu. Here is what i want to do.

On hover a link (#mylink) i want to display a div (lets call it \"#submenu\") right under

4条回答
  •  春和景丽
    2020-12-29 17:31

    If you put #submenu inside of #mylink you won't need a second event handler for #submenu and you would have something like this:

    var timer;
    $(document).ready(function()
    {
        $('#mylink').hover(function()
        {
            clearTimeout(timer);
            $('#submenu').show();
        },function()
        {
            timer = setTimeout(function(){$('#submenu').hide();},5000);
        });
    }
    

    By the way, you don't need jQuery for this. In plain js won't be so long to code.

提交回复
热议问题