Skip to content

Commit

Permalink
Merge pull request #3145 from harshshukla06/main
Browse files Browse the repository at this point in the history
Updated navbar.js
  • Loading branch information
deepeshmlgupta authored Nov 9, 2024
2 parents 177ef61 + c8894bb commit 55a63f8
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions navbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,18 @@ overlay.addEventListener("click", function() {
overlay.style.visibility = "hidden";
});

window.addEventListener("scroll", function() {
// Debounce function
function debounce(func, wait = 20) {
let timeout;
return function() {
const context = this, args = arguments;
clearTimeout(timeout);
timeout = setTimeout(() => func.apply(context, args), wait);
};
}

// Scroll event with debounce
window.addEventListener("scroll", debounce(function() {
const navbar = document.querySelector(".navbar-collapse");
const navLinks = document.querySelectorAll(".navbar-nav .nav-item a");

Expand All @@ -53,14 +64,13 @@ window.addEventListener("scroll", function() {
link.style.color = "#edf2f4";
});
}
});
}, 20)); // 20ms delay for debounce

function toggleDropdown(show) {
const dropdownMenu = document.querySelector('.dropdown-menu');
if (show) {
dropdownMenu.style.display = 'block';
} else {
dropdownMenu.style.display = 'none';
}
}


}

0 comments on commit 55a63f8

Please sign in to comment.