1

I want to delay an animation that slides an image in a li a-element. I had the idea, that I could go through every li element with a counter (i) and set a timeout with the animation to do: 1000 + i * 50

Unfortunately only the last li-element will be animated. Why is that?

li = $('nav ul li').get();
lic = li.length;

$('nav ul li a .icon').hide();

t = [];
for (i = 0; i < li.length; i++) {
    var obj = $('nav ul li')[i];

    t[i] = setTimeout(function() {
        $(obj).children('a').children('.icon').slideDown();
    }, 1000 + i * 50);

    delete obj;
}
2
  • Why are you wrapping an already jQuery object in another jQuery constructor? Commented Jun 27, 2012 at 21:23
  • To clarify things, delete obj will not do anything because delete will only remove properties, not variables. Commented Jun 27, 2012 at 21:26

2 Answers 2

3

This should be fine:

jsBin demo

$('nav ul li a .icon').hide();

$('nav ul li').each(function( i ){       
    $(this).find('.icon').delay(i*300).slideDown();    
});
Sign up to request clarification or add additional context in comments.

1 Comment

@RokoC.Buljan - $(this).find(".icon") is faster.
0

Try this, and this is no a full code, and un-tested. Please borrow the logic from this..

$('nav ul li').each(function {
    $(this).find("a>.icon").hide();
    t[i] = setTimeout(function() {
        $(this).find("a>.icon").slideDown();
    }, 1000 + i * 50);
});

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.