Created
November 9, 2011 22:18
-
-
Save codeincontext/1353299 to your computer and use it in GitHub Desktop.
Function to repeatedly rotate between frames in an animation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Making a note of this as it uses mod, rather than resetting i to 0 when i == length