forked from Code-Social/official-website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
32 lines (28 loc) · 1018 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
28
29
30
31
32
document.addEventListener("DOMContentLoaded", () => {
const navbarItems = document.querySelectorAll(".navbar ul li");
const navbar = document.querySelector(".navbar ul");
const toggleButton = document.querySelector(".toggle-button");
const hamburgerImg = document.getElementById("hamburger-img");
navbarItems.forEach((item) => {
item.addEventListener("mouseover", () => {
const dropdown = item.querySelector(".dropdown");
if (dropdown) {
dropdown.style.display = "block";
}
});
item.addEventListener("mouseout", () => {
const dropdown = item.querySelector(".dropdown");
if (dropdown) {
dropdown.style.display = "none";
}
});
});
// Toggle hamburger menu on small screens
toggleButton.addEventListener("click", () => {
navbar.classList.toggle("active");
const isNavbarActive = navbar.classList.contains("active");
hamburgerImg.src = isNavbarActive
? "/images/close.png"
: "/images/hamburger.png";
});
});