-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjavascript.js
More file actions
36 lines (33 loc) · 1.13 KB
/
javascript.js
File metadata and controls
36 lines (33 loc) · 1.13 KB
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
function constructGrid(s){
const main = document.querySelector(".main")
const container = document.createElement("div");
container.id = "container";
main.appendChild(container);
let cellSide = Math.floor(720/s);
let width = cellSide*s + 'px';
container.style.width = width;
container.style.height = width;
for(let i = 1; i <= s*s; i++){
const div = document.createElement("div");
div.style.width = cellSide + 'px';
div.style.height = cellSide + 'px';
container.appendChild(div);
}
container.addEventListener("mouseover", (e) => {
if(e.target !== container) {
e.target.style.backgroundColor = "black";
}
});
}
const applybtn = document.querySelector("#applybtn");
applybtn.addEventListener("click", () =>{
container.remove();
const gridSize = document.querySelector("#grid-size").value;
constructGrid(gridSize);
});
const resetbtn = document.querySelector("#resetbtn");
resetbtn.addEventListener("click", () => {
container.remove();
const gridSize = document.querySelector("#grid-size").value;
constructGrid(gridSize);
})