Slide to a certain position to fix the navigation bar flicker?

I encountered a problem when writing an example. Because there is a click on the secondary navigation to load more, resulting in the navigation bar fixed in advance, I wrote the height of the navigation bar from the top of the document to the onscroll before the problem is gone, but there is a navigation bar flickering problem, ask the god to give advice.
this is the code that is fixed in advance


    var nav=$(".agenda .erji-nav");
    var navST=$(".agenda .erji-nav").offset().top;
    $(window).scroll(function(){
        if($(document).scrollTop()+80>navST){
            nav.addClass("hahaha");
        }
        else if($(document).scrollTop()+80<=navST){
            nav.removeClass("hahaha");
            
        }
    });

the navigation bar should be fixed from here

clipboard.png

clipboard.png

then I wrote var navST=$ (".room. erji-nav"). Offset (). Top; on $(window). Scroll ()
when I was sliding the page, the navigation bar began to flash, I tried several ways but failed, ask the boss to show me the way

Mar.17,2021

is this because sroll triggers frequently

?
if($(document).scrollTop()+80>navST){
    nav.addClass("hahaha");
}
else if($(document).scrollTop()+80<=navST){
    nav.removeClass("hahaha");
    
}

in this paragraph, I think you can take a look at function anti-shaking and function throttling. I hope I can help you


Hello, have you solved your problem? Now I have the same problem. When the element changes to a fixed position and then slides, it flashes

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e462b3-44b80.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e462b3-44b80.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?