jQuery奇怪的延迟行为

时间:2014-11-26 23:00:25

标签: jquery delay

我与delay()发生了奇怪的错误。我有网站,我在延迟添加图像src与这样的功能:

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

在主页上它按预期工作,但在单页上它只是在没有任何延迟的情况下同时添加图像src。

我在这里做错了什么,或者我错过了什么?

1 个答案:

答案 0 :(得分:2)

jQuery docs隐含地声明延迟 NOT 超时并且仅用于动画

你想要达到的目标是:

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

setTimeout(doSomething, 200);

编辑:

$('.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));
});
相关问题