Last active
November 23, 2015 21:20
-
-
Save joshdcomp/2624c6b1434e1d5c0e83 to your computer and use it in GitHub Desktop.
making increments smaller
This file contains 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
var decremancer = function(iterations, unit, time) { | |
for (var i = 0; i < iterations; i++) { | |
//set increments to `unit` | |
} | |
//where you'd determine the rate things get smaller | |
var newTime = time - 100; | |
//stop when the time gets too small | |
if (newTime < 0) return; | |
//DECROMANCE | |
var newUnit = unit - 1; | |
setTimeout( function(){ | |
decremancer(iterations, newUnit, newTime) | |
}, newTime); | |
} | |
var iterations = 200; | |
var unit = 20; | |
var time = 2000; | |
// kick things off | |
decremancer(); |
This file contains 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
var decremancer = function(iterations, unit) { | |
for (var i = 0; i < iterations; i++) { | |
//set increments to `unit` | |
} | |
} | |
var time = 2000; | |
var _unit = 20; | |
//setting interval to a variable is helpful for cancelling it at some point | |
var interval = setInterval(function(){ | |
if (_unit -1 < 0) return; | |
unit = _unit - 1; | |
decremancer(20, unit); | |
}, time); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment