-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
jessicarush
committed
Feb 4, 2020
1 parent
726281b
commit f694c21
Showing
4 changed files
with
47 additions
and
14 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,24 @@ | ||
function randomBg() { | ||
|
||
// Generate a random number between 0 and given number (inclusive) | ||
function random(n) { | ||
return Math.floor(Math.random() * (n + 1)); | ||
} | ||
|
||
// Generate a random rgb color | ||
function randomRGB() { | ||
let rgbColor = 'rgb(' + random(255) + ',' + random(255) + ',' + random(255) + ')'; | ||
let rgbColor = `rgb(${random(255)}, ${random(255)}, ${random(255)})`; | ||
return rgbColor; | ||
} | ||
|
||
// Set an elements --random-bg property to a random color | ||
function changeBg() { | ||
let els = document.querySelectorAll('.color-box'); | ||
for (el of els) { | ||
function changeBg(selector) { | ||
let els = document.querySelectorAll(selector); | ||
for (let el of els) { | ||
el.style.setProperty('--random-bg', randomRGB()); | ||
} | ||
|
||
} | ||
changeBg(); | ||
changeBg('.color-box'); | ||
} | ||
|
||
randomBg(); |