Skip to content

Instantly share code, notes, and snippets.

@SteGriff
Created April 11, 2018 09:08
Show Gist options
  • Select an option

  • Save SteGriff/45dda9e5bb782667e669fa7d76fddf14 to your computer and use it in GitHub Desktop.

Select an option

Save SteGriff/45dda9e5bb782667e669fa7d76fddf14 to your computer and use it in GitHub Desktop.
Vanilla JS loading indicator using Unicode clocks
<!DOCTYPE HTML>
<html>
<head>
<title></title>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
.big{font-size:120%;}
</style>
</head>
<body>
<main>
<p class="js-clock big"></p>
</main>
<script>
function clock()
{
var clockInterval = null;
var num = 0;
var frames = ["πŸ•","πŸ•‘","πŸ•’","πŸ•“","πŸ•”","πŸ••","πŸ•–","πŸ•—","πŸ•˜","πŸ•™","πŸ•š","πŸ•›"];
this.start = function(element)
{
clockInterval = window.setInterval(advance, 100);
}
this.stop = function()
{
if (clockInterval)
{
window.clearInterval(clockInterval);
}
}
var advance = function()
{
num++;
num %= frames.length;
element.innerText = frames[num];
}
}
var c = new clock();
var element = document.getElementsByClassName("js-clock")[0];
c.start(element);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment