From e49073fa32c34afb973464b01ef830c12cbf96bb Mon Sep 17 00:00:00 2001 From: Taras Kachmar <107129371+TarasKachmar2022@users.noreply.github.com> Date: Fri, 8 Mar 2024 23:25:58 +0200 Subject: [PATCH] fix --- src/js/smooth-scroll.js | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/js/smooth-scroll.js b/src/js/smooth-scroll.js index cad82ea..0e4214c 100644 --- a/src/js/smooth-scroll.js +++ b/src/js/smooth-scroll.js @@ -6,24 +6,26 @@ document.querySelectorAll('a.site-nav__link').forEach(link => { const scrollTarget = document.getElementById(href); - let headerTopOffset = 0; - headerTopOffset = topOffsetSelector(); + let topOffset = 0; + topOffset = topOffsetSelector(); const elementPosition = scrollTarget.getBoundingClientRect().top; - const offsetPosition = elementPosition - headerTopOffset; + const offsetPosition = elementPosition - topOffset; window.scrollBy({ top: offsetPosition, behavior: 'smooth' }); }); +}); + +function topOffsetSelector() { + const viewportWidth = window.innerWidth; - function topOffsetSelector() { - const viewportWidth = window.innerWidth; + let headerTopOffset; - if (viewportWidth >= 768) { - headerTopOffset = 82; - return headerTopOffset; - } else { - headerTopOffset = 104; - return headerTopOffset; - } + if (viewportWidth >= 768) { + headerTopOffset = 82; + return headerTopOffset; + } else { + headerTopOffset = 104; + return headerTopOffset; } -}); +}