Skip to content

Instantly share code, notes, and snippets.

@thanos
Created November 11, 2011 21:05
Show Gist options
  • Select an option

  • Save thanos/1359266 to your computer and use it in GitHub Desktop.

Select an option

Save thanos/1359266 to your computer and use it in GitHub Desktop.
javascript - runs the function, worker, through a number of steps with a delay between each step. Can be used to cycle through images.
/*
* runs the function, worker, through a number of steps with a delay between each step.
* This example flicks through a bunch of images.
* step(0,10, function(num, stop) {
* $('#mo').attr('src', 'images/'+num+'.jpg');
* }, 600);
*/
function step(ind, stop, worker, delay) {
if (ind < stop) {
setTimeout(function(){
worker(ind, stop);
step(ind + 1, stop, worker, delay);
}, delay);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment