Created
October 31, 2012 01:00
-
-
Save oreshinya/3984164 to your computer and use it in GitHub Desktop.
closure for 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 Counter() { | |
| var count = 0; | |
| return function() { | |
| count += 1; | |
| return count; | |
| } | |
| } | |
| function startAnimation(func, duration, animation_size, params) { | |
| var animationCounter = Counter(); | |
| var animation_timer = null; | |
| var animate = function() { | |
| var animation_index = animationCounter(); | |
| if (animation_size !== "infinite" && animation_index > animation_size) { | |
| clearInterval(animation_timer); | |
| } else { | |
| func(animation_index, params); | |
| } | |
| } | |
| animate(); | |
| animation_timer = setInterval(animate, duration); | |
| $(document).bind("loadpanel", function() { | |
| clearInterval(animation_timer); | |
| }); | |
| } | |
| function animateHoge(animation_index, params) { | |
| //write some code | |
| } | |
| startAnimation(animateHoge, 1000, 8, {target: hoge}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment