From f10739ac2c99d565b045d8794287e19397a6dea4 Mon Sep 17 00:00:00 2001 From: kkrzowski Date: Wed, 29 Oct 2025 10:03:45 +0100 Subject: [PATCH] init :) --- index.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 index.js diff --git a/index.js b/index.js new file mode 100644 index 0000000..eeb8c5b --- /dev/null +++ b/index.js @@ -0,0 +1,24 @@ +function hideHeaderOnScroll() { + const header = document.querySelector('header'); + if (!header) return; + + let lastScrollY = window.scrollY; + let offset = 0; + const headerHeight = header.offsetHeight; + + function onScroll() { + const currentScroll = window.scrollY; + const diff = currentScroll - lastScrollY; + + offset += diff; + offset = Math.max(0, Math.min(offset, headerHeight)); + + header.style.transform = `translateY(-${offset}px)`; + + lastScrollY = currentScroll; + } + + window.addEventListener('scroll', onScroll); +} + +document.addEventListener('DOMContentLoaded', hideHeaderOnScroll); \ No newline at end of file