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

35 lines
1017 B
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-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');
} else {
if(lastScrollPosition < 5) {
iconBar.classList.add('st-icon-bar-sticky');
siteTitle.classList.add('st-title-scrolled');
}
}
2024-06-20 22:15:11 +00:00
lastScrollPosition = scrollPosition;
});