Looping with .each with delay in Jquery

后端 未结 5 1026
时光说笑
时光说笑 2021-01-16 14:20

I am not good at jQuery so I am not sure if my assumptions are corrent.

I am using the isotope plugin, with which I want to insert elements one by one (and not every

5条回答
  •  隐瞒了意图╮
    2021-01-16 14:39

    $("#items_are_here").find('.item').each(function( index ) {
         setTimeout(function() {
                $('#container').isotope( 'insert', $(this));
             },3000);
        });
    

    in the above context, $(this) is the window object, because it's inside setTimeout.

    Modify your code to and try:

    $("#items_are_here").find('.item').each(function( index ) {
         var item = $(this);
         setTimeout(function(index) {
                $("#container").isotope( 'insert', $(this))
         },index*3000);
        });
    

提交回复
热议问题