treehouse : what would you like to learn today?
Web Design Web Development iOS Development

How to callback properly? (and timeout)

  • Hi all,

    I'm having some trouble understanding how the callback works. This is a quite simple example, doesn't work as I want it to though. My idea is that box2 should animate back when the two first (and simoltaneous, spelling) animations complete, however it doesn't.

    Another question is how will I delay the callback by say two seconds? And is it possible to loop this over and over again?

    $('#elevator').click(function(){
    $('#box1').animate({width: 250, height: 300}, 1000);
    $('#box2').animate({width: 200, height: 300}, 1000);
    }, function(){
    $('#box2').animate({width: 300, height: 10}, 1000);
    }
    );
  • I wouldn't even class myself a beginner with jQuery, thats why I always look at the documentation.

    Go to their site and search those specific terms (call backs, delays, queue), study all there examples carefully. I know everytime I have a problem, I always use this process.

    Hope this helps in some indirect way.
  • you could try this...

    $('#elevator').click(function(){
    $('#box1').animate({width: 250, height: 300}, 1000);
    $('#box2').animate({width: 200, height: 300}, 1000)
    .animate({width: 300, height: 10}, 1000);
    }
    );


    bit of a random guess tbh lol