CodeIgniter Forums
iterate through array for jQuery animations?. - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: iterate through array for jQuery animations?. (/showthread.php?tid=45786)



iterate through array for jQuery animations?. - El Forum - 10-05-2011

[eluser]umbungo[/eluser]
I am trying to do successive animations based on the contents of an array. Here is what i thought it should have been;
Code:
arr = [ "First", "Second", "Third", "Forth" ];
for(index in arr){
    $('#fade').fadeOut(2000, function(){
        $('#fade').html(arr[index]).fadeIn(2000);
    });
}
However this fades straight to 'fourth', presumably because it iterates through the array without waiting for the animations. What should i be doing instead?