Skip to content

Instantly share code, notes, and snippets.

@oreshinya
Created October 31, 2012 01:00
Show Gist options
  • Select an option

  • Save oreshinya/3984164 to your computer and use it in GitHub Desktop.

Select an option

Save oreshinya/3984164 to your computer and use it in GitHub Desktop.
closure for animation
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