0

I'm trying to animate elements sequentially by using jQuery. The approach that I'm trying to accomplish is to add "animated fadeInDown" classes on each element that should be animated, with a 500 milisecond delay.

The problem that I'm experiencing is that jQuery (or if I use setTimetout function) will trigger all animations at the same time.

Here's my code:

$('.row-assets .asset').each(function(i) {
    $(this).delay((i++) * 500).addClass('animated').addClass('fadeInDown');
});

What am I doing wrong?

1
  • depending on your skill level and available time, maybe check out the GreenSock jQuery animation library - greensock.com Commented Jul 4, 2014 at 16:30

1 Answer 1

1

addClass() is not part of the jQuery animation queue, and is therefore not affected by delay(). A proper use of setTimeout should work:

DEMO

var addClassToEl = function($el) {
    $el.addClass('animated fadeInDown');
};

$('.row-assets .asset').each(function(i, el) {
    setTimeout(function() {addClassToEl($(el))}, i++ * 500);
});

You'll have to make sure that your classes have appropriate CSS transitions on them if you want to animate their changes.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.