-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
76 lines (60 loc) · 2.17 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
const cgrid = document.querySelector('#container');
const gridInput = document.getElementById('grid-size');
const gridValue = gridInput.value;
let color = document.querySelector('#color-picker');
function addGrid(row, column) {
cgrid.style.setProperty('grid-template-columns', `repeat(${column}, 1fr)`);
cgrid.style.setProperty('grid-template-rows', `repeat(${row}, 1fr)`);
for (let i = 0; i < (row * column); i++) {
const div = document.createElement('div');
div.classList.add('grid');
cgrid.appendChild(div);
}
hoverGrid();
}
function changeGrid(row, column) {
row = gridInput.value;
column = gridInput.value;
if (row > 0 && row < 65 && column > 0 && column < 65) {
document.querySelectorAll(".grid")
.forEach((e) => e.parentNode.removeChild(e));
addGrid(row, column);
}
else {
var snackbar = document.getElementById('snackbar');
snackbar.className = "show";
setTimeout(function () { snackbar.className = snackbar.className.replace("show", ""); }, 3000);
}
}
function hoverGrid() {
let item = document.querySelectorAll('.grid');
item.forEach(item => item.addEventListener('mouseover', () => {
item.style.backgroundColor = color.value;
}));
}
function randomColor() {
let item = document.querySelectorAll('.grid');
item.forEach(item => item.addEventListener('mouseover', () => {
for (let i = 0; i < 10; i++) {
const randomColor = "#" + Math.floor(Math.random() * 16777215).toString(16);
item.style.backgroundColor = randomColor;
}
}));
}
function colorGrid() {
let item = document.querySelectorAll('.grid');
item.forEach(item => item.addEventListener('mouseover', () => {
item.style.backgroundColor = color.value;
}));
}
function eraseGrid() {
let item = document.querySelectorAll('.grid');
item.forEach(item => item.addEventListener('mouseover', () => {
item.style.backgroundColor = 'transparent';
}));
}
function resetGrid() {
let item = document.querySelectorAll('.grid');
item.forEach(item => item.style.backgroundColor = 'transparent');
};
addGrid(16, 16);