-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
34 lines (27 loc) · 898 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
32
33
34
const board = document.querySelector('#board')
const colors = ['#00FA9A', '#FF0000', '#FFFF00', '#1E90FF', '#FAEBD7', '#BC8F8F']
const SQUARES_NUMBER = 1000
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 = gerRandomColor()
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 gerRandomColor() {
const index = Math.floor(Math.random() * colors.length)
return colors[index]
}