-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
27 lines (23 loc) · 930 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
let isMenuOpen = false;
function toggleDropdown() {
let dropdown = document.getElementById("myDropdown");
dropdown.classList.toggle("show-dropdown");
let dropdownIcon = document.getElementsByClassName("expand-icon")[0];
dropdownIcon.textContent = isMenuOpen ? "expand_more" : "keyboard_arrow_up";
isMenuOpen = !isMenuOpen;
}
// Close the dropdown if the user clicks outside of it
window.onclick = function (event) {
if (!event.target.matches(".dropdown-btn")) {
let dropdowns = document.getElementsByClassName("dropdown-content");
let dropdownIcon = document.getElementsByClassName("expand-icon")[0];
for (let i = 0; i < dropdowns.length; i++) {
let openDropdown = dropdowns[i];
if (openDropdown.classList.contains("show-dropdown")) {
openDropdown.classList.remove("show-dropdown");
dropdownIcon.textContent = "expand_more";
isMenuOpen = false;
}
}
}
};