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

66 lines
2.5 KiB
JavaScript
Raw Normal View History

2024-07-01 20:18:30 +00:00
//Nav slide in logic
const nav = document.querySelector('.st-nav');
const openNavButton = document.querySelector('.st-open-nav');
const closeNavButton = document.querySelector('.st-close-nav');
openNavButton.addEventListener('click', () => {
nav.classList.add('st-nav-is-open');
});
closeNavButton.addEventListener('click', () => {
nav.classList.remove('st-nav-is-open');
});
//Search slide logic
const searchOverlay = document.querySelector('.st-search-overlay');
const openSearchButton = document.querySelector('.st-open-search');
const closeSearchButton = document.querySelector('.st-close-search');
openSearchButton.addEventListener('click', () => {
searchOverlay.classList.add('st-search-is-open');
});
closeSearchButton.addEventListener('click', () => {
searchOverlay.classList.remove('st-search-is-open');
});
//Sticky nav logic
const iconBar = document.querySelector('.st-header-icon-bar');
const siteTitle = document.querySelector('.st-site-title');
2024-07-22 19:41:07 +00:00
const siteTitleBall = document.querySelector('.st-site-title__ball');
2024-07-01 20:18:30 +00:00
const header = document.querySelector('.st-header');
2024-07-23 21:31:45 +00:00
const topper = document.querySelector('.st-article-section-topper');
2024-07-24 19:17:49 +00:00
const desktopNavLinks = document.querySelector('.st-desktop-nav-links');
2024-07-01 20:18:30 +00:00
let lastScrollPosition = 0;
2024-07-22 19:41:07 +00:00
const scrollDepthActivationPoint = 80;
2024-07-01 20:18:30 +00:00
window.addEventListener('scroll', function(event) {
const scrollPosition = window.scrollY;
2024-07-02 20:45:52 +00:00
if(scrollPosition < scrollDepthActivationPoint) {
2024-07-01 20:18:30 +00:00
iconBar.classList.remove('st-icon-bar-sticky');
siteTitle.classList.remove('st-title-scrolled');
header.classList.remove('st-header-scrolled');
2024-07-22 19:41:07 +00:00
siteTitleBall.classList.remove('st-title-scrolled__ball');
2024-07-23 21:31:45 +00:00
topper.classList.remove('st-article-section-topper-scrolled');
2024-07-24 19:17:49 +00:00
desktopNavLinks.classList.remove('st-desktop-nav-links-scrolled');
2024-07-01 20:18:30 +00:00
} else {
2024-07-02 20:45:52 +00:00
if(lastScrollPosition < scrollDepthActivationPoint) {
2024-07-01 20:18:30 +00:00
iconBar.classList.add('st-icon-bar-sticky');
siteTitle.classList.add('st-title-scrolled');
header.classList.add('st-header-scrolled');
2024-07-22 19:41:07 +00:00
siteTitleBall.classList.add('st-title-scrolled__ball');
2024-07-23 21:31:45 +00:00
topper.classList.add('st-article-section-topper-scrolled');
2024-07-24 19:17:49 +00:00
desktopNavLinks.classList.add('st-desktop-nav-links-scrolled');
2024-07-01 20:18:30 +00:00
}
}
lastScrollPosition = scrollPosition;
2024-07-24 18:29:01 +00:00
});
const navItems = document.querySelectorAll('.st-header-icon-bar__item');