Mateusz Winnicki
Mateusz Winnicki

Reputation: 151

jQuery strange delay behaviour

I'm having strange error with delay(). I have website where I add images src on delay with function like that:

  $('.attachment-full').each(function(indexs) { 
var visible_pathz = $(this).attr('data-info');
$(this).delay(200*indexs).attr('src', visible_pathz).fadeIn(300);   
});

On home page It does work as expected, but on single page It just adds images src at the same time without any delay.

What did I do wrong here, or what do I miss ?

Upvotes: 0

Views: 35

Answers (1)

ymz
ymz

Reputation: 6914

jQuery docs implicitly states that delay is NOT a timout and should use for animations ONLY

what you are trying to achive is that:

function doSomething()
{
   // place your code here
}

setTimeout(doSomething, 200);

EDIT:

$('.attachment-full').each(function(indexs) 
{ 
    var visible_pathz = $(this).attr('data-info');

    setTimeout(function(e)
    {          
        e.attr('src', visible_pathz).fadeIn(300);

    }, 200 * indexs, $(this));
});

Upvotes: 2

Related Questions