-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathindex.js
29 lines (26 loc) · 922 Bytes
/
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
// Add this to your existing JavaScript file
document.addEventListener("DOMContentLoaded", function () {
const toggleMenu = document.querySelector(".toggle-menu");
const navLinks = document.querySelector(".nav-links");
const dropdowns = document.querySelectorAll(".dropdown");
// Toggle mobile menu
toggleMenu.addEventListener("click", function () {
navLinks.classList.toggle("active");
});
// Handle dropdowns on mobile
dropdowns.forEach((dropdown) => {
dropdown.addEventListener("click", function (e) {
if (window.innerWidth <= 768) {
e.preventDefault();
this.classList.toggle("active");
}
});
});
// Close menu when clicking outside
document.addEventListener("click", function (e) {
if (!e.target.closest("nav")) {
navLinks.classList.remove("active");
dropdowns.forEach((dropdown) => dropdown.classList.remove("active"));
}
});
});