-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
107 lines (91 loc) · 2.98 KB
/
script.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
let container = document.getElementById("wrapper");
let size = document.getElementById("sizeRange");
let allButtons = document.querySelector('.topSelectors')
let box = document.getElementById("wrapper").children;
let rainbowButton = document.getElementById("rainbow");
let userColor = document.getElementById("color");
let allColor = document.getElementById("allCol");
let cleaner = document.getElementById("cleaner");
let resetButton = document.querySelector("#reset");
let toggleGrid = document.querySelector("#gridLine");
function createGrid() {
container.innerHTML = ""
let gridval = document.getElementById("gridval");
let gridSize = size.value
let gridBoxes = gridSize * gridSize;
gridval.innerHTML = gridSize;
container.style.display = "grid"
container.style.gridTemplateColumns = `repeat(${gridSize}, 1fr)`
container.style.gridTemplateRows = `repeat(${gridSize},1fr)`
for(let i = 0; i < gridBoxes; i++) {
let cell = document.createElement("div");
cell.classList.add("square")
let opacity = .2
cell.addEventListener ("mouseenter", function(){
cell.style.background = "rgba(0,0,0,"+opacity+")";
opacity +=.2
})
container.appendChild(cell);
}
}
createGrid()
function eraser() {
for(let item of box) {
item.addEventListener("mouseenter", function() {
item.style.backgroundColor = ""
})
}
}
function colorChoice() {
for(let prop of box) {
prop.addEventListener("mouseenter", function() {
prop.style.backgroundColor = userColor.value ;
})
}
}
function randomColors() {
function red() {
return Math.floor(Math.random() * 255)
}
function green() {
return Math.floor(Math.random() * 255)
}
function blue() {
return Math.floor(Math.random() * 255)
}
for (const element of box) {
element.addEventListener("mouseenter", function(){
element.style.backgroundColor = `rgb(${red()}, ${green()}, ${blue()} )`
})
}
}
function rainbowColors() {
let rainbow = ["red", "orange", "yellow", "green", " blue", "indigo", "violet"]
function i() {
let i = Math.floor(Math.random() * 7);
return i
}
for(let item of box) {
item.addEventListener("mouseenter", function(){
item.style.backgroundColor = rainbow[i()]
})
}
}
function reset() {
for(let items of box) {
items.style.backgroundColor = ""
}
}
function toggleLine() {
for(let item of box) {
item.classList.toggle("gridLines")
}
}
size.addEventListener("click", createGrid)
rainbowButton.addEventListener("click", rainbowColors);
cleaner.addEventListener("click", eraser);
userColor.addEventListener("click", colorChoice);
allColor.addEventListener("click", randomColors);
resetButton.addEventListener("click", reset);
toggleGrid.addEventListener("click", toggleLine);
rainbowButton.addEventListener("click", rainbowColors)