Skip to content

Instantly share code, notes, and snippets.

@walterm
Last active December 19, 2015 01:59
Show Gist options
  • Save walterm/5879588 to your computer and use it in GitHub Desktop.
Save walterm/5879588 to your computer and use it in GitHub Desktop.
var interval = 6000;
var g = this.group;
var fall = true;
var callBack = function(){
return function(){
//Making it alternate between falling and going all the way back to the top instantaneously
if(fall){
//Falling
g.transition().duration(interval).ease('linear').attr('transform', 'translate(0,3000)');
fall = false;
}else {
//Resetting
g.transition().duration(0).attr('transform', 'translate(0,-1000)');
fall = true;
interval = 6000;
}
d3.timer(callBack(),interval);
//Timer also executes the function until it returns true
return true;
};
};
//Timer executes the specified function after the specified number of seconds has passed
//In this case, I want it to start falling immediately
d3.timer(callBack(), 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment