This repository has been archived by the owner on Mar 18, 2024. It is now read-only.
forked from iamabhi898/Colour-Generator-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
126 lines (87 loc) · 3.77 KB
/
app.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// BASIC COLOURS =>
// White(#FFFFFF) Red(#FF0000) Yellow(#FFFF00) Green(#00FF00) Blue(#0000FF) Orange(#FFA500) Purple(#800080) Black(#000000)
// Color Palette
const colorPicked = document.querySelectorAll(".color");
const colorName = document.querySelector("h1");
const hexCode = document.querySelector(".hexCode");
const body = document.querySelector("body");
for (const colorElement of colorPicked) {
colorElement.addEventListener("click", function () {
// light mode
const btn = document.querySelector(".clickMe");
btn.style.borderColor = "#1b262c";
btn.style.color = "whitesmoke";
if (colorElement.classList.contains("white")) {
body.style.backgroundColor = "white";
colorName.textContent = "White";
colorName.style.color = "white";
hexCode.textContent = "Colour : #FFFFFF";
} else if (colorElement.classList.contains("red")) {
body.style.backgroundColor = "red";
colorName.textContent = "Red";
colorName.style.color = "red";
hexCode.textContent = "Colour : #FF0000";
} else if (colorElement.classList.contains("yellow")) {
body.style.backgroundColor = "yellow";
colorName.textContent = "Yellow";
colorName.style.color = "yellow";
hexCode.textContent = "Colour : #FFFF00";
} else if (colorElement.classList.contains("green")) {
body.style.backgroundColor = "green";
colorName.textContent = "Green";
colorName.style.color = "green";
hexCode.textContent = "Colour : #00FF00";
} else if (colorElement.classList.contains("blue")) {
body.style.backgroundColor = "blue";
colorName.textContent = "Blue";
colorName.style.color = "blue";
hexCode.textContent = "Colour : #0000FF";
} else if (colorElement.classList.contains("orange")) {
body.style.backgroundColor = "orange";
colorName.textContent = "Orange";
colorName.style.color = "orange";
hexCode.textContent = "Colour : #FFA500";
} else if (colorElement.classList.contains("purple")) {
body.style.backgroundColor = "purple";
colorName.textContent = "Purple";
colorName.style.color = "purple";
hexCode.textContent = "Colour : #800080";
} else if (colorElement.classList.contains("black")) {
body.style.backgroundColor = "black";
colorName.textContent = "Black";
colorName.style.color = "black";
hexCode.textContent = "Colour : #000000";
// dark mode
const btn = document.querySelector(".clickMe");
btn.style.borderColor = "whitesmoke";
btn.style.color = "whitesmoke";
}
});
}
/************ Random Color *************/
const hex = [
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", "C", "D", "E", "F"
]
const randColor = document.querySelector(".random");
randColor.addEventListener("click", function () {
let hexColorCode = '#';
for (let i = 0; i < 6; i++) {
let j = Math.floor(Math.random() * 16);
hexColorCode += hex[j];
}
body.style.backgroundColor = hexColorCode;
colorName.textContent = "";
hexCode.textContent = "Colour : " + hexColorCode;
});
/***************** Click Me - Random *****************/
const btn = document.querySelector(".clickMe");
btn.addEventListener("click", function () {
let hexColorCode = '#';
for (let i = 0; i < 6; i++) {
let j = Math.floor(Math.random() * 16);
hexColorCode += hex[j];
}
body.style.backgroundColor = hexColorCode;
colorName.textContent = "";
hexCode.textContent = "Colour : " + hexColorCode;
});