-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
31 lines (24 loc) · 887 Bytes
/
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
const board = document.querySelector('#board');
const colors = ['#0dcaf0', '#8262e0', '#0dcaf0', 'cyan', '#68e0cf', '#229efd', '#0064b9', 'magenta']
const SQUARES_NUMBER = 750;
for (let i = 0; i < SQUARES_NUMBER; i++) {
const square = document.createElement('div');
square.classList.add('square');
square.addEventListener('mouseover', setColor);
square.addEventListener('mouseleave', removeColor);
board.append(square);
}
function setColor(event) {
const element = event.target;
const color = getRandomColor();
element.style.backgroundColor = color;
element.style.boxShadow = `0 0 2px ${color}, 0 0 10px ${color}`;
}
function removeColor(event) {
const element = event.target;
element.style.backgroundColor = '#1d1d1d';
element.style.boxShadow = `0 0 2px #000`;
}
function getRandomColor() {
return colors[Math.floor(Math.random() * colors.length)];
}