Skip to content

Instantly share code, notes, and snippets.

@codeincontext
Created November 9, 2011 22:18
Show Gist options
  • Select an option

  • Save codeincontext/1353299 to your computer and use it in GitHub Desktop.

Select an option

Save codeincontext/1353299 to your computer and use it in GitHub Desktop.
Function to repeatedly rotate between frames in an animation
function startAnimation() {
var i = 0;
var frameId = 0;
frames = $('.animation').find('li');
setInterval(function(){
if (frames.length) {
$(frames[frameId]).css('opacity', '0');
frameId = i++ % frames.length;
$(frames[frameId]).css('opacity', '1');
}
},1500);
}
@codeincontext

Copy link
Copy Markdown
Author

Making a note of this as it uses mod, rather than resetting i to 0 when i == length

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment