Created
January 14, 2016 18:50
-
-
Save chaoslogick/b42bf46f97e3254b617a to your computer and use it in GitHub Desktop.
JS: Randomize DOM BG color
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
function changeBGColor() { | |
document.bgColor = document.colorChange.text.value; | |
document.colorChange.colorValue.value = ''; | |
} | |
function randomBG() { | |
var h1 = new Array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'); | |
var h2 = new Array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'); | |
var h3 = new Array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'); | |
var h4 = new Array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'); | |
var h5 = new Array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'); | |
var h6 = new Array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'); | |
var bg='#'+h1[Math.floor(Math.random()*h1.length)]+h2[Math.floor(Math.random()*h2.length)]+h3[Math.floor(Math.random()*h3.length)]+h4[Math.floor(Math.random()*h4.length)]+h5[Math.floor(Math.random()*h5.length)]+h6[Math.floor(Math.random()*h6.length)]; | |
document.bgColor = bg; | |
} | |
function timedChange() { | |
hexChanger = setInterval('randomBG()', 10); // Speed Adjustment | |
} | |
function timedChangeStop() { | |
clearInterval(hexChanger); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment