Created
November 7, 2020 19:33
-
-
Save jelinski/4ee27befb0df0a4f0011aead18477259 to your computer and use it in GitHub Desktop.
Function that creates a rainbow clock on element given its ID
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
var createTimeUpdater = function (clockId){ | |
var clockElement = document.getElementById(clockId); | |
var rainbowColors = [ | |
"#FF0000", | |
"#FF7F00", | |
"#FFFF00", | |
"#00FF00", | |
"#0000FF", | |
"#2E2B5F", | |
"#8B00FF" | |
]; | |
var index = 0; | |
return function(){ | |
clockElement.innerText = (new Date()).toLocaleTimeString(); | |
clockElement.style.color = rainbowColors[index]; | |
index= (index + 1) % rainbowColors.length; | |
}; | |
}; | |
setInterval(createTimeUpdater("clock"), 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment