1

How can I get one script of jQuery to start after another one has finished (or time it when you want it to start)? I have a content area that fades in on page load:

$(document).ready(function() {

    $("#content").hide();

    $(window).load(function() {
        $("#content").fadeIn(3000);
    });

});

Than, once that fades in I want the nav bar above the content area to slide toggle down. I'm trying to make the scripts act in accordance with the timing of one another. OK, thank you.

matchew
  • 19,195
  • 5
  • 44
  • 48
Graham
  • 1,433
  • 3
  • 21
  • 34

2 Answers2

3

Use .fadeIn()'s callback:

$("#content").fadeIn(
    3000,
    function() {
       //do stuff here
    }
);
kei
  • 20,157
  • 2
  • 35
  • 62
  • Got it, thank man. Is there a way so the content doesn't slide down to. So, it's fixed where it's gonna be after the slideToggle? – Graham Jun 29 '11 at 22:04
  • Show more code. I know nothing about the placement of your html elements. – kei Jun 29 '11 at 22:34
  • I can't really put the coded here cause it's too many characters. But it's http://www.paulbedal.com. The who page slides down when the the #nav-top slidetoggles down. I don't want the page to slide down like that. – Graham Jun 29 '11 at 22:58
  • woh that's a really application. Wow, a CSS issue. I can't believe I did that. All I needed was the #nav-top-wrapper (as you displayed) to push down the #content. Thanks so much man! – Graham Jun 30 '11 at 00:04
  • Also, is there a way to acivate $("#nav-top").slideDown(); 1500 ms after page load even if #content is set for 3000ms on pageload? So, it #nav-top would load before #content is finished loading. Thanks again – Graham Jun 30 '11 at 00:08
1
$(document).ready(function() {

$("#content").hide();

$(window).load(function() {
    $("#content").fadeIn(3000, function() {

       $('#navBar').slideDown('slow')
      });
   });
});

.fadeIn() allows you to specify a function to be called once its complete. is the $(window).load() necessary here with $(document).ready()?

matchew
  • 19,195
  • 5
  • 44
  • 48
  • I suppose, I often give the right answer, and then edit the question several times as I build on it. Its just my style. For example, http://stackoverflow.com/questions/6497525/print-date-for-the-monday-of-the-current-week-in-bash/6497622#6497622 I edited quite a bit as I thought of more. unfortunately the answer was already accepted before the following line was added: `#although, if you fancy yourself an Abraham Lincolin date -d'monday-fortnight' +%Y%m%d #2 weeks ago` – matchew Jun 29 '11 at 21:44