-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
56 lines (49 loc) · 1.61 KB
/
index.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
50
51
52
53
54
55
56
function toggleNav() {
var navBar = document.getElementById("myTopnav");
var icon = navBar.querySelector(".icon");
if (navBar.classList.contains("open")) {
// Close the navbar
navBar.classList.remove("open");
icon.textContent = "☰"; // Change back to "☰" when closing
} else {
// Open the navbar
navBar.classList.add("open");
icon.textContent = "✕"; // Change to "✕" when opening
}
if (navBar.classList.contains("responsive")) {
navBar.classList.remove("responsive");
} else {
navBar.classList.add("responsive");
}
}
var clickedBtnId = [];
const clickableDivs = document.querySelectorAll('.box3_');
console.log(clickableDivs)
var isReverting = false;
clickableDivs.forEach((div) => {/*traversal of complete 9 boxes*/
div.addEventListener('click', function () {
console.log(div);
if (isReverting) return;
if (div.id === "b9") {/*when b9 clicked reverting become true and start traversing from zero*/
isReverting = true;
retracePath(0);
} else {
handleButtonClick(div);
clickedBtnId.push(div);
}
});
});
function retracePath(idx) {
if (idx === clickedBtnId.length) {/*when completely traverse the array array become empty */
clickedBtnId = [];
isReverting = false;
return;
}
clickedBtnId[idx].style.backgroundColor = "#00407A";
setTimeout(() => {
retracePath(idx + 1);
}, 500);/* after every .5second the color changes*/
}
function handleButtonClick(div) {
div.style.backgroundColor = "red";
}