-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
100 lines (87 loc) · 2.81 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Project:Etch-a-Sketch</title>
<link
rel="icon"
href="pngtree-futuristic-glowing-protection-abstract-sphere-net-png-image_12216790.png"
type="image/x-icon"
/>
<style>
body {
display: flex;
flex-direction: column;
gap: 20px;
background-color: #ffffffb1;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
#choosing_button {
border-radius: 20px;
background-color: rgb(238, 237, 229);
font-weight: 700;
color: black;
padding: 10px;
}
.grid_Container {
display: flex;
height: 600px;
width: 600px;
border : 2px solid black;
flex-wrap: wrap;
}
.grid_item {
border: 1px solid rgb(255, 255, 255);
box-sizing: border-box;
}
</style>
<script src="script.js"></script>
</head>
<body>
<button id="choosing_button">Sqaures per side</button>
<div class="grid_Container"></div>
<script>
const gridsParent = document.querySelector(".grid_Container");
// gridsParent.style.cssText = "background-color:#b9dfee";
let prevOpacity = 0.0001;
for (let i = 1; i <= 16 * 16; i++) {
const grid_box = document.createElement("div");
grid_box.setAttribute("class", "grid_item");
grid_box.style.cssText = `width:${600 / 16}px;height:${600 / 16}px;border:0.3px solid black`;
grid_box.addEventListener('mouseenter',()=>{
let presentOpacity;
if(prevOpacity < 1){
presentOpacity = parseFloat(prevOpacity)+0.1;
}else{
presentOpacity = 0;
}
console.log("opacity presently is ",presentOpacity);
//feature added of randomizing the sqr color on every interaction
const color = getRandomColor();
console.log("Random color is",color);
grid_box.style.backgroundColor = `${color}`;
grid_box.style.opacity = `${presentOpacity}`;
let computedStyle = window.getComputedStyle(grid_box);
prevOpacity = computedStyle.opacity;
console.log("prev opacity is ",prevOpacity);
}
);
gridsParent.appendChild(grid_box);
function getRandomColor(){
const letter = "0123456789ABCDEF";
let color = '#';
for(let i=0;i<6;i++){
const randomIndex = Math.floor(Math.random() * 16);
// console.log(`Random index: ${randomIndex}, Letter: ${letter[randomIndex]}`);
color += letter[randomIndex];
}
return color;
}
}
</script>
</body>
</html>