-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogic.js
49 lines (44 loc) · 1.62 KB
/
logic.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
let container = document.querySelector('.container');
let btn = document.getElementById('gridBtn');
let resetBtn = document.getElementById('resetBtn');
let rainbowBtn = document.getElementById("rainbowBtn");
rainbowBtn.addEventListener('click', rainbowColor)
resetBtn.addEventListener('click', reset)
btn.addEventListener('click',createGrid);
function createGrid(){
let usrChoice = parseInt(prompt("Enter layout 1-100: "));
container.innerHTML = "";
if (usrChoice <= 100){
for (let i = 0; i<(usrChoice*usrChoice); i++){
const content = document.createElement('div');
content.classList.add('box')
container.appendChild(content);
}
}
//---hover start---
let boxes = document.getElementsByClassName('box')
for (let a = 0; a<boxes.length; a++){
boxes[a].style.height = 700/usrChoice+"px";
boxes[a].style.width = 700/usrChoice+"px";
boxes[a].addEventListener('mouseover', ()=>{
boxes[a].style.backgroundColor = "#00FFFFFF";
});
}
//---hover end---
}
function reset(){
let boxes = document.getElementsByClassName('box')
for (let a = 0; a<boxes.length; a++){
boxes[a].classList.remove('hover');
boxes[a].style.backgroundColor = "#E3CEB9";
}
}
function rainbowColor(){
let boxes = document.getElementsByClassName('box')
for (let a = 0; a<boxes.length; a++){
let randomColor = Math.floor(Math.random()*16777215).toString(16);
boxes[a].addEventListener('mouseover', () =>{
boxes[a].style.backgroundColor = "#" + randomColor;
});
}
}