Last active
October 24, 2016 15:43
-
-
Save joshschmelzle/f5ac7499c6cd9cad28a220f216179b27 to your computer and use it in GitHub Desktop.
A simple spinner animation with JavaScript and HTML
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 a = ["~", "/", "|", "\"]; | |
// - : - | |
// ~ : ~ | |
var asyncLoop = function(o) { | |
var i = -1; | |
var loop = function() { | |
i++; | |
if (i == o.length) { | |
o.callback(); | |
return; | |
} | |
o.functionToLoop(loop, i); | |
} | |
loop(); //init | |
} | |
var start = setInterval(function() { | |
asyncLoop({ | |
length: 4, | |
functionToLoop: function(loop, i) { | |
setTimeout(function() { | |
document.getElementById("spin").innerHTML = a[i]; | |
loop(); | |
}, 75); | |
}, | |
callback : function(){ | |
} | |
}) | |
}, 300); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample usage:
<span id="spin"></span>
Sample css:
#spin { font-size: 5em; font-family: monospace; }
https://jsfiddle.net/schmelzle/puvyuc4z/