如何以500毫秒的间隔fadeIn()表行

时间:2014-07-02 12:58:57

标签: ajax settimeout fadein

以下代码获取一段包含一定数量行的html。其中一些行是newentry类。 (class="newentry") 我期待我的代码以1000米延迟显示它们,但它们都同时出现。为什么setTimeout没有在每次调用每行fadeIn()之间等待?

$.ajax({
    url: "@{Live.live(event.mnemonic)}",
    success: function(data) {
        var wait =0;
        $("#results").html(data);

        wait =500;
        $(".newentry").each(function(){
            setTimeout(function() { $('#'+this.id).fadeIn(); }, wait);
            wait += 1000;
        });

        }
        setTimeout('tick()', 1700-wait);
    }
});

1 个答案:

答案 0 :(得分:0)

试试这个

$(".newentry").hide(); 
$.ajax({
    url: "@{Live.live(event.mnemonic)}",
    success: function(data) {
        $("#results").html(data);
        i=500;
        $('.newentry').each(function(){
            setTimeout(function(){delayedShow($(this))},i);
            i=i+500;
        });
        {
    } 
}); 
function delayedShow(obj) { obj.fadeIn(); }
相关问题