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

162
Views
How to hide and show div when scrolling using jQuery or JS

I want to make a container that needs to hide when scrolling-down and needs to show scrolling-up. If not scrolling, I want it to be visible.

Here is my code block.

$.fn.scrollEnd = function(callback, timeout) {
  $(this).scroll(function() {
    var $this = $(this);
    if ($this.data('scrollTimeout')) {
      clearTimeout($this.data('scrollTimeout'));
    }
    $this.data('scrollTimeout', setTimeout(callback, timeout));
  });
};

$(window).scroll(function() {
  $('#navbar').fadeOut();
});

$(window).scrollEnd(function() {
  $('#navbar').fadeIn();
}, 700);
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet"/>

<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.8.3/font/bootstrap-icons.css" rel="stylesheet"/>

<!--add by me 26/05/22-->
<div id="navbar">
  <footer class="mobile_footer">
    <div class="mobile_footer_inner">
      <nav class="navbar fixed-bottom bg-white">
        <a href="#" class="menu_item">
          <i class="bi bi-house"></i>
        </a>
        <a href="#" class="menu_item">
          <i class="bi bi-chat-dots"></i>
        </a>
        <a href="/Ad/PostAd" class="menu_item menu_item__middle_plus">
          <i class="bi bi-plus-circle"></i>
        </a>
        <a href="#" class="menu_item">
          <i class="bi bi-bookmark"></i>
        </a>
        <a href="#" class="menu_item">
          <i class="bi bi-person"></i>
        </a>
      </nav>
    </div>
  </footer>
</div>
<!--end-->

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>

My scripts works fine but it works in different way and type!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Use this code to hide navbar when scrolling and, show it when you have stopped scrolling.

window.addEventListener("scroll", function () {
  $("#navbar").fadeOut();     //hide when scrolling

  clearTimeout($.data(this, 'scrollTimer'));
    $.data(this, 'scrollTimer', setTimeout(function() {
      $("#navbar").fadeIn(); 
    }, 550));   //show after this much milliseconds when scrolling has stopped
});

Working Example

about 4 years ago · Juan Pablo Isaza Report
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!