I have set up a simple function to add a class to header when scrolling some amounts of pixels from the top of the document, it works everywhere but not in Edge. Any ideas why that is ?
No errors in the console, nothing, just doesn't work.
const headerScrollClass = () => {
window.addEventListener('scroll', throttle(callback, 100));
}
function throttle(fn, wait) {
let time = Date.now();
return function () {
if ((time + wait - Date.now()) < 0) {
fn();
time = Date.now();
}
}
}
const callback = () => {
if (document.documentElement.scrollTop > 100) {
document.querySelector('.header').classList.add('header--top');
} else {
document.querySelector('.header').classList.remove('header--top');
}
}