From a37b37ebb7e7176732815c9615188a9d083148d6 Mon Sep 17 00:00:00 2001 From: Prayash007 Date: Fri, 18 Oct 2024 11:46:42 +0530 Subject: [PATCH] #153 --- scripts/index.js | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/scripts/index.js b/scripts/index.js index 79996fe..b7a5ceb 100644 --- a/scripts/index.js +++ b/scripts/index.js @@ -26,7 +26,7 @@ overlay.style.display = "none"; }); - const close = document.querySelectorAll(".navclose"); + document.getElementById("openMenu").addEventListener("click", function () { document.getElementById("menuContainer").style.display = "flex"; }); @@ -34,8 +34,12 @@ document.getElementById("closeMenu").addEventListener("click", function () { document.getElementById("menuContainer").style.display = "none"; }); - document.querySelectorAll(".close").addEventListener("click", function () { - document.getElementById("menuContainer").style.display = "none"; + + // Ensure all elements with the class 'close' close the menu + document.querySelectorAll(".close").forEach((closeButton) => { + closeButton.addEventListener("click", function () { + document.getElementById("menuContainer").style.display = "none"; + }); }); function handleClose() { @@ -47,8 +51,11 @@ const nav = document.querySelector('nav'); const whereWePlantSection = document.querySelector('.locations'); + let lastScrollTop = 0; // To track the last scroll position + // Function to add/remove dark background function handleScroll() { + const currentScrollTop = window.pageYOffset || document.documentElement.scrollTop; const sectionTop = whereWePlantSection.getBoundingClientRect().top; const threshold = window.innerHeight * 0.1; @@ -57,6 +64,16 @@ } else { nav.classList.remove('dark'); } + + if (currentScrollTop > lastScrollTop) { + // User is scrolling down, hide the navbar + nav.style.top = "-100px"; // Adjust based on navbar height + } else { + // User is scrolling up, show the navbar + nav.style.top = "0"; + } + + lastScrollTop = currentScrollTop; } window.addEventListener('scroll', handleScroll); \ No newline at end of file