简体   繁体   English

一次消失附加元素

[英]Fading in appended elements one at a time

I have an array with IDs and I am loading elements with these IDs from another page. 我有一个ID数组,我正在从另一页加载具有这些ID的元素。

    $.each(idArr, function() {
        var divline = '<div class="line" id="' + this + '">';
        var url = 'allitems.php #' + this + ' div';
        $('#the-list').append($(divline).load(url).hide().fadeIn());
    });

It works fine but I would like the loaded elements to fade in one at a time, or at least not all att once. 它工作正常,但我希望加载的元素一次消失一次,或者至少不是一次全部消失。 I cannot figure out how to use .delay with my code. 我无法弄清楚如何在我的代码中使用.delay。 Or is there maybe another way? 还是有另一种方式?

Thank you :) 谢谢 :)

A simple solution is to use setTimeout : 一个简单的解决方案是使用setTimeout

$.each(idArr, function(i) {
    var divline = '<div class="line" id="' + this + '">';
    var url = 'allitems.php #' + this + ' div';
    setTimeout(function(){
        $('#the-list').append($(divline).load(url).hide().fadeIn());
    }, i*1000);
});

尝试这种方式:

$(".elements").each(function(i, e) { $(e).delay(i * 400).fadeIn(400); });
$.each(idArr, function(i,el) {
    var divline =  $('<div />', {'class':'line', id: el}),
        url = 'allitems.php #' + el + ' div';
    $('#the-list').append(divline.load(url).hide().delay(i*1000).fadeIn());
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM