jQuery animate one another another

Im trying to animate one elment after another, but I have some troubles with this

    $.getJSON('http://localhost/json/example/json.json', function(data){
        var ele = jsonElements(data);
        for(var i = 1; i <= ele; i++)
        {
            $('#test').append('<a href="#" id="t_'+i+'" class="block-icon"></a>');
            $('#t_'+i).animate({
                'top': data['t_'+i]['top'],
                'left': data['t_'+i]['left']
                }, 800).delay(1000);
        }

    });

It works, but all elements have animation in same time, any advice how to make it one after another?

Answers


$.getJSON('http://localhost/json/example/json.json', function(data){
        var ele = jsonElements(data);
        one_by_one(ele,1);
    });

function one_by_one(ele,i){
if(i > ele)
return;

$('#test').append('<a href="#" id="t_'+i+'" class="block-icon"></a>');
$('#t_'+i).animate({
                'top': data['t_'+i]['top'],
                'left': data['t_'+i]['left']
                }, 1000, function() {
    // Animation complete
    one_by_one(ele,i+1);
  });

}

call one_by_one(i);

I added an example on http://jsfiddle.net/VS8tQ/64/


Need Your Help

Looping through list of entities in a ViewModel

c# asp.net-mvc entity-framework razor

One of my entities Create page needs to have a list of other entities, in this case the Timetable create view needs a list of Station entities. To achieve this I created my own ViewModel: