Created
April 11, 2018 09:08
-
-
Save SteGriff/45dda9e5bb782667e669fa7d76fddf14 to your computer and use it in GitHub Desktop.
Vanilla JS loading indicator using Unicode clocks
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
| <!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