From 6cb0c42521fd48b74ed658e8325ec81c9e0acaff Mon Sep 17 00:00:00 2001 From: Ross Trottier Date: Fri, 21 Jun 2024 10:57:39 -0600 Subject: [PATCH] sticky header --- assets/js/st-nav.js | 18 +++++++++++++++++- header.php | 3 +-- style.css | 30 +++++++++++++++++++++++++----- 3 files changed, 43 insertions(+), 8 deletions(-) diff --git a/assets/js/st-nav.js b/assets/js/st-nav.js index c721121..13851d7 100644 --- a/assets/js/st-nav.js +++ b/assets/js/st-nav.js @@ -1,3 +1,5 @@ +//Nav slide in logic + const nav = document.querySelector('.st-nav'); const openButton = document.querySelector('.st-open-nav'); const closeButton = document.querySelector('.st-close-nav'); @@ -10,10 +12,24 @@ closeButton.addEventListener('click', () => { nav.classList.remove('st-nav-is-open'); }); +//Sticky nav logic + +const iconBar = document.querySelector('.st-header-icon-bar'); +const siteTitle = document.querySelector('.st-site-title'); let lastScrollPosition = 0; window.addEventListener('scroll', function(event) { const scrollPosition = window.scrollY; - console.log(scrollPosition); + + if(scrollPosition < 5) { + iconBar.classList.remove('st-icon-bar-sticky'); + siteTitle.classList.remove('st-title-scrolled'); + } else { + if(lastScrollPosition < 5) { + iconBar.classList.add('st-icon-bar-sticky'); + siteTitle.classList.add('st-title-scrolled'); + } + } + lastScrollPosition = scrollPosition; }); \ No newline at end of file diff --git a/header.php b/header.php index aa81c8f..936526c 100644 --- a/header.php +++ b/header.php @@ -29,9 +29,8 @@ - -

Slowtwitch

+

Slowtwitch