slowtwitch-news/assets/js/st-nav.js

38 lines
1.2 KiB
JavaScript
Raw Normal View History

2024-06-21 16:57:39 +00:00
//Nav slide in logic
2024-06-20 22:15:11 +00:00
const nav = document.querySelector('.st-nav');
const openButton = document.querySelector('.st-open-nav');
const closeButton = document.querySelector('.st-close-nav');
openButton.addEventListener('click', () => {
nav.classList.add('st-nav-is-open');
});
closeButton.addEventListener('click', () => {
nav.classList.remove('st-nav-is-open');
});
2024-06-21 16:57:39 +00:00
//Sticky nav logic
const iconBar = document.querySelector('.st-header-icon-bar');
const siteTitle = document.querySelector('.st-site-title');
2024-06-21 20:56:00 +00:00
const header = document.querySelector('.st-header');
2024-06-20 22:15:11 +00:00
let lastScrollPosition = 0;
window.addEventListener('scroll', function(event) {
const scrollPosition = window.scrollY;
2024-06-21 16:57:39 +00:00
if(scrollPosition < 5) {
iconBar.classList.remove('st-icon-bar-sticky');
siteTitle.classList.remove('st-title-scrolled');
2024-06-21 21:09:21 +00:00
header.classList.remove('st-header-scrolled');
2024-06-21 16:57:39 +00:00
} else {
if(lastScrollPosition < 5) {
iconBar.classList.add('st-icon-bar-sticky');
siteTitle.classList.add('st-title-scrolled');
2024-06-21 20:56:00 +00:00
header.classList.add('st-header-scrolled');
2024-06-21 16:57:39 +00:00
}
}
2024-06-20 22:15:11 +00:00
lastScrollPosition = scrollPosition;
});