Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

231
Views
Is there a more performance friendly way to write this jQuery script?

I am using this code to show/hide the header on scroll but the header is slightly glitchy, the code is from an article written in 2013 so I don't know if that's the cause...

function hasScrolled() {
  var l = $(this).scrollTop();
  Math.abs(lastScrollTop - l) <= delta ||
    (l > lastScrollTop && l > navbarHeight
      ? $("header").removeClass("nav-down").addClass("nav-up")
      : l + $(window).height() < $(document).height() &&
        $("header").removeClass("nav-up").addClass("nav-down"),
    (lastScrollTop = l));
}

var didScroll,
  lastScrollTop = 0,
  delta = 5,
  navbarHeight = $("header").outerHeight();

$(window).scroll(function (l) {
  didScroll = !0;
});

setInterval(function () {
  didScroll && (hasScrolled(), (didScroll = !1));
}, 250);

Thanks in advance :)

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!