javascript - setTimeout() in for each loop doesn't work -
i have make board assignment lights 1 1 sci-fi movie “close encounters of third kind”. main objective here specific blocks light in specific order 2 second interval between them code have done now:
$(document).ready(function () { var colorblocks = [ 'yellow', 'green', 'blue', 'white', 'orange' ] $.each(colorblocks, function (i) { $('#' + this).css("background", this); // when use alert can see boxes change color 1 one // alert(something); }); }); but doesn't seem work changes colour of boxes @ once unless if alert(something);
can help?
i think want this:
$.each(colorblocks, function (i) { settimeout(function() { $('#' + this).css("background", this); }.bind(this), * 2000); }); why i * 2000?
i iteration's index, it'll wait i * 2000 ms each call next "animation" occur.
Comments
Post a Comment