-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
36 lines (28 loc) · 1.05 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
const board = document.querySelector('#board')
const colors = ['#1abc9c', '#4efc53', '#3498db', '#9b59b6', '#ff3f34', '#f1c40f', '#f57e33', '#48dbfb']
const SQUARES_NUMBER = 600
for (let i = 0; i < SQUARES_NUMBER; i++) {
const square = document.createElement('span')
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 10px ${color}, 0 0 15px ${color}`
board.style.boxShadow = `0 0 30px 30px ${color}, 0 0 600px 100px ${color}`
board.style.transition = '.2s linear'
}
function removeColor(event) {
const element = event.target
element.style.backgroundColor = '#1d1d1d'
element.style.boxShadow = `0 0 2px #000`
board.style.boxShadow = '0 0 40px 10px #000'
board.style.transition = `1s linear`
}
function getRandomColor() {
return colors[Math.floor(Math.random() * colors.length)]
}