I'm trying this on my website to make my header sticky but hide while scrolling. On line 4 I'm getting this error Uncaught TypeError: $ is not a function
I don't know what I'm messing up with
let didScroll;
let lastScrollTop = 0;
let delta = 5;
let navbarHeight = $('header').outerHeight();
window.scroll(function(event){
didScroll = true;
});
setInterval(function() {
if (didScroll) {
hasScrolled();
didScroll = false;
}
}, 250);
function hasScrolled() {
let st = this.scrollTop();
if(Math.abs(lastScrollTop - st) <= delta)
return;
if (st > lastScrollTop && st > navbarHeight){
$('header').classList.remove("nav-down").classList.add("nav-up");
} else {
if(st + window.height() < document.height()) {
$('header').classList.remove("nav-up").classList.add("nav-down");
}
}
lastScrollTop = st;
}