const headerTop = document.querySelector('.header__top');
const headerSubstrate = document.querySelector('.header__substrate');
let lastScrollTop = 0;
function headerScroll() {
window.addEventListener('scroll', () => {
let scrollDistance = window.scrollY;
if (scrollDistance > lastScrollTop) {
headerTop.classList.remove('header__top-active');
headerSubstrate.style.top = '-200px';
} else {
headerTop.classList.add('header__top-active');
headerSubstrate.style.top = '0px';
}
lastScrollTop = scrollDistance;
});
}
const mediaQuery = window.matchMedia('(min-width: 768px)')
if (mediaQuery.matches) {
headerScroll()
} else {
}
function headerScroll() {
let headerTop = null;
let headerSubstrate = null;
let lastScrollTop = 0;
function onScroll() {
let scrollDistance = window.scrollY;
if (scrollDistance > lastScrollTop) {
headerTop.classList.remove('header__top-active');
headerSubstrate.style.top = '-200px';
} else {
headerTop.classList.add('header__top-active');
headerSubstrate.style.top = '0px';
}
lastScrollTop = scrollDistance;
}
function init() {
destroy();
headerTop = document.querySelector('.header__top');
headerSubstrate = document.querySelector('.header__substrate');
lastScrollTop = 0;
window.addEventListener('scroll', onScroll);
}
function destroy() {
window.removeEventListener('scroll', onScroll);
}
return { init, destroy };
}
const { init: initStickyHeader, destroy: destroyStickyHeader } = headerScroll();
const mediaQuery = window.matchMedia('(min-width: 768px)');
mediaQuery.addEventListener('change', (event) => {
if (event.matches) {
initStickyHeader();
} else {
destroyStickyHeader();
}
});