-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
32 lines (23 loc) · 973 Bytes
/
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
const board = document.querySelector('#board');
const colors = ['#ff0000', '#ff9100', '#f6ff00', '#40ff00', '#00ff80', '#00ffff', '#006aff', '#0400ff', '#9000ff', '#f200ff', '#ff009d'];
const SQUARES_NUMBER = 400;
for (let i = 0; i < SQUARES_NUMBER; i++) {
const square = document.createElement('div');
square.classList.add('square');
square.addEventListener('mouseover', () => setColor(square));
square.addEventListener('mouseleave', () => removeColor(square));
board.append(square);
}
function setColor(element) {
const color = getRandomColor();
element.style.backgroundColor = color;
element.style.boxShadow = `0 0 2px ${color}, 0 0 10px ${color}`;
}
function removeColor(element) {
element.style.backgroundColor = '#1d1d1d';
element.style.boxShadow = '0 0 2px #000';
}
function getRandomColor() {
const index = Math.floor(Math.random() * colors.length);
return colors[index];
}