1

What's wrong with this string: items[i].addClass('in'); ? it's killing me! I was tring different ways with .each(); for example but it's still fail...

if(layer = 'aboutAuthor') {
    var items = $('.aboutAuthor .item');
    var K = 100; // Коэфициент.
    var t = K * (items.length + 1);
    for (var i = items.length - 1; i >= 0; i--) {
        console.log(items[i]);
        setTimeout(function(){
            items[i].addClass('in');
        }, t);
        t += K;
    }
}

strange moment that console.log() displays each element in logs as expected, and normal. HELP!

north.inhale
  • 483
  • 2
  • 9
  • 20
  • 1
    Also `if(layer = 'aboutAuthor')` doesn't seem right and `items[i].addClass` should be something like `$(items[i]).addClass` – Musa Dec 20 '14 at 18:24

1 Answers1

1

I tried to not change the code too much, but I had assumed that you wanted to change the items in reverse.

if(layer === 'aboutAuthor') {
    var items = $('.aboutAuthor .item');
    var K = 100; // Коэфициент.
    var t = K * (items.length + 1);
    var i = items.length - 1;
    $(items.get().reverse()).each(function() {
        var item = $(this);
            console.log(item);
            setTimeout(function(){
                item.addClass('in');
            }, t);
            t += K;
        }
    });
}
Vince
  • 416
  • 2
  • 5