CLiown
CLiown

Reputation: 13843

Lots of nested functions can I make this simpler

Here is the jQuery I've written to animate some items in a list:

$("#titleTile").delay(5000).animate({top: "160px"}, 300, function() {
  $(".tweet_msg.t0").animate({top: 0, height: "show"}, 300, function() {
    $(".tweet_msg.t1").delay(5000).animate({top: 0, height: "show"}, 300, function() {
      $(".tweet_msg.t2").delay(5000).animate({top: 0, height: "show"}, 300, function() {
        $(".tweet_msg.t3").delay(5000).animate({top: 0, height: "show"}, 300, function() { 
          $(".tweet_msg.t4").delay(5000).animate({top: 0, height: "show"}, 300);
        });
      });
    });
  });
});

Is there a better way to write my code?

Secondly can I wrap it up into a function that I could call?

Upvotes: 1

Views: 69

Answers (1)

James Montagne
James Montagne

Reputation: 78650

The other option would be to use a custom queue on a single element. May be overkill if this is all you are doing. But if you want to, here is a small example I had created for a previous question:

http://jsfiddle.net/jRawX/2/

http://api.jquery.com/queue/

As far as wrapping it in a function, sure, just wrap it in a function:

function something(){
    // do your stuff
}

Upvotes: 3

Related Questions