Search code examples
jqueryhtmlscrolldelay

I want to delay a link using jquery


I have a navigation menu on top of the page that redirects within a page. However, some of the divs are initially hidden and take 1 second to appear so the anchor tag doesn't move the browser window down far enough. I want to delay the link for a second to wait for the div to be visible before the window scrolls down.

The divs are opened using

$.slideToggle(1000)

and the nav menu uses a simple

<a href='#divid'>link to divid</a>

Solution

  • Use the set timeout function, and give it a delay before firing the next event.

    $("#divid").bind("click", function() {
        setTimeout(function() {
            $("#divid").slideToggle(1000);
        },1000);
    });