Last active
December 16, 2015 00:48
-
-
Save endocrimes/5350025 to your computer and use it in GitHub Desktop.
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
| <script type="text/javascript"> | |
| (function () { | |
| var Tickr = { | |
| run: function (opts) { | |
| var el = opts.el; | |
| if(!el) return; | |
| var start = Date.now(), delta; | |
| var target = opts.target; | |
| var duration = opts.duration; | |
| var outputType = (el.nodeName.toLowerCase() === 'input') ? 'value' : 'innerHTML'; | |
| var currentVal = +el[outputType] || 0; | |
| var tickr = setInterval(function () { | |
| delta = Date.now() - start; | |
| if(delta >= duration) { | |
| clearInterval(tickr); | |
| return el[outputType] = target; | |
| } | |
| el[outputType] = (currentVal + ((delta * (target-currentVal)) / duration)).toFixed(0); | |
| }, 10); | |
| } | |
| }; | |
| window.Tickr = Tickr; | |
| })(); | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment