0

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;
}
  • *sticky but hide while scrolling* those are complete opposites. That's like "I'm trying to hide my header but show it" – freedomn-m Mar 24 '22 at 06:25
  • Does this help: [missing jquery in typescript](https://stackoverflow.com/a/49260659/2181514) – freedomn-m Mar 24 '22 at 06:27
  • Seems you haven't imported jQuery, or an error occurred during importing. – Shrimp Mar 24 '22 at 07:41
  • Does this answer your question? [$ is not a function - jQuery error](https://stackoverflow.com/questions/3931529/is-not-a-function-jquery-error) – Mushroomator Mar 26 '22 at 01:30

0 Answers0