From b7a875c75eb2440e278fe759b09b92c13fadcfa9 Mon Sep 17 00:00:00 2001 From: Mykola Zahorulko Date: Wed, 20 Aug 2025 15:26:36 +0200 Subject: [PATCH] Add sticky header feature --- .idea/.gitignore | 8 ++++++++ sticky-header/index.less | 36 +++++++++++++++++++++++++++++++++ sticky-header/steacky-header.js | 20 ++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 sticky-header/index.less create mode 100644 sticky-header/steacky-header.js diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/sticky-header/index.less b/sticky-header/index.less new file mode 100644 index 0000000..9860b62 --- /dev/null +++ b/sticky-header/index.less @@ -0,0 +1,36 @@ +@media(min-width: 978px) { + .desktop-menu__scroll{ + #container{ + padding-top: 26.4rem; // Write here your header element height value + } + + header{ + position: fixed; + top: 0; + left: 0; + animation: stickyAnimation 0.5s; + .responsive-padding(); // Function with padding, added in the repository as well + + &:before { + position: fixed; + top: 0; + left: 0; + animation: stickyAnimation 0.5s; + max-height: 100px; + } + + .bars_top.bars, .breadcrumbs, .idm-help, .top-bar{ + display: none !important; + } + } + } +} + +@keyframes stickyAnimation { + 0% { + transform: translate(0, -100%); + } + 100% { + transform: translate(0, 0); + } +} \ No newline at end of file diff --git a/sticky-header/steacky-header.js b/sticky-header/steacky-header.js new file mode 100644 index 0000000..4f101ef --- /dev/null +++ b/sticky-header/steacky-header.js @@ -0,0 +1,20 @@ +const HEADER_POINT = 70; +let lastScrollY = window.scrollY; + +window.addEventListener("scroll", () => { + if (app_shop.vars.view === 1 || app_shop.vars.view === 2) return; + + const container = document.querySelector("#container"); + if (container.classList.contains("projector_page")) return; + + const bodyEl = document.querySelector("body"); + const currentScroll = window.scrollY; + + if (currentScroll < lastScrollY && currentScroll > HEADER_POINT) { + bodyEl.classList.add("desktop-menu__scroll"); + } else { + bodyEl.classList.remove("desktop-menu__scroll"); + } + + lastScrollY = currentScroll; +}); \ No newline at end of file