-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandom_variables.js
58 lines (49 loc) · 1.43 KB
/
random_variables.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// ------------------------------
// VARIABLES PLACE
// ------------------------------
// 'DOM ELEMENT'
const
rootElement = document.documentElement,
fab = document.querySelector('.fabutton')
// 'CSS VARIABLES'
const cssVarSet = [
{
primaryColor: "#000",
firstColor: "#CDB4DB",
secondColor: "#FFC8DD",
thirdColor: "#FFAFCC",
fourthColor: "#BDE0FE",
fifthColor: "#A2D2FF"
},
{
primaryColor: "#000",
firstColor: "#CCD5AE",
secondColor: "#E9EDC9",
thirdColor: "#FEFAE0",
fourthColor: "#FAEDCD",
fifthColor: "#D4A373"
},
{
primaryColor: "#fff",
firstColor: "#002029",
secondColor: "#00303D",
thirdColor: "#004052",
fourthColor: "#005066",
fifthColor: "#00607A"
}
]
// ------------------------------
// EVENT LISTENER
// ------------------------------
// => change the variables of the root element
fab.addEventListener('click', ()=>{
// => create a random number between 0 and 2
let randomNumber = Math.floor(Math.random() * 3)
alert(`random css variable set "-- ${randomNumber +1} --" is selected`)
// => select a random css var set
let cssRandomVarSet = cssVarSet[randomNumber]
// => replace the css variables of the root element
for (const key in cssRandomVarSet){
rootElement.style.setProperty(`--${key}`, cssRandomVarSet[key]);
}
})