From da9595d58641bc5f57e81fb088466eddc33bc2a7 Mon Sep 17 00:00:00 2001 From: Dinkar Date: Wed, 20 Nov 2024 22:22:32 +0530 Subject: [PATCH] thresold decreased for centered position, close navBar when clicked on navItem --- scripts/dynamicallyLoadChunks.js | 2 +- scripts/script.js | 35 +++++++++++++++++++++----------- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/scripts/dynamicallyLoadChunks.js b/scripts/dynamicallyLoadChunks.js index 76171b6..bff166d 100644 --- a/scripts/dynamicallyLoadChunks.js +++ b/scripts/dynamicallyLoadChunks.js @@ -36,7 +36,7 @@ function isDivCenteredVertically(div) { const divCenter = rect.top + rect.height / 2; // Check if the div center is approximately equal to the viewport center - const threshold = 200; // Allow some small tolerance for "centered" + const threshold = 125; // Allow some small tolerance for "centered" return Math.abs(viewportCenter - divCenter) <= threshold; } const scrollListener = throttleDebounce(function (project) { diff --git a/scripts/script.js b/scripts/script.js index 0d5815a..641e52c 100644 --- a/scripts/script.js +++ b/scripts/script.js @@ -43,19 +43,30 @@ window.onscroll = function () { } }; -const hamburgerMenuIcon = document.querySelector('.hamburger-menu-icon'); -const mNavBar = document.querySelector('#mNavBar'); -const mNavBarOverlay = document.querySelector('.m-nav-bar-overlay'); -hamburgerMenuIcon.onclick = () => { - mNavBar.classList.add('show'); - mNavBarOverlay.classList.add('show'); -}; -const navbarCloseIcon = document.querySelector('#navbarCloseIcon'); -navbarCloseIcon.onclick = mNavBarOverlay.onclick = () => { - mNavBar.classList.remove('show'); - mNavBarOverlay.classList.remove('show'); -}; +(() => { + const hamburgerMenuIcon = document.querySelector('.hamburger-menu-icon'); + const mNavBar = document.querySelector('#mNavBar'); + const mNavBarOverlay = document.querySelector('.m-nav-bar-overlay'); + const navbarCloseIcon = document.querySelector('#navbarCloseIcon'); + const mNavBarLinks = mNavBar.querySelectorAll('.nav-links > a'); + + function show_mNavBar() { + mNavBar.classList.add('show'); + mNavBarOverlay.classList.add('show'); + }; + + function close_mNavBar() { + mNavBar.classList.remove('show'); + mNavBarOverlay.classList.remove('show'); + }; + + hamburgerMenuIcon.onclick = show_mNavBar; + + mNavBarLinks.forEach((navLink) => { navLink.onclick = close_mNavBar }); + navbarCloseIcon.onclick = mNavBarOverlay.onclick = close_mNavBar; +})(); + window.onload = () => { const hash = window.location.hash;