Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #1181013

    Hello! Is it possible to have the normal header, then make it disappear when the user scrolls down, and then reappear (the shrinked version) as soon as the user scrolls up a bit? Like the one you find here https://www.itsnicethat.com/

    thanks!

    #1181192

    any idea about this?

    #1181680

    Hi studiono,

    Can you try adding this code in your child theme’s functions.php:

    function hide_show_header(){
    ?>
    <script>
    jQuery( document ).ready(function( $ ) {
      var didScroll;
      var lastScrollTop = 0;
      var delta = 5;
      var navbarHeight = $('#header').outerHeight();
    
      $(window).scroll(function(event){
        didScroll = true;
      });
    
      setInterval(function() {
        if (didScroll) {
          hasScrolled();
          didScroll = false;
        }
      }, 250);
    
      function hasScrolled() {
        var st = $(this).scrollTop();
        
        if(Math.abs(lastScrollTop - st) <= delta)
          return;
        
        if (st > lastScrollTop && st > navbarHeight){
          $('#header').fadeOut("fast");
        } else {
          if(st + $(window).height() < $(document).height()) {
            $('#header').fadeIn("fast");
          }
        }
        
        lastScrollTop = st;
      }
    });
    </script>
    <?php
    }
    add_action('wp_footer', 'hide_show_header', 100);

    Best regards,
    Nikko

    #1181701

    WOW nikko that’s great – there’s only one thing that I would link being different: now the header disappear a fraction of second after being shrined (so you see normal header > shrinked version > fading). Is it possible to make it go fading while still big? You can check the link in the private content area here

    THANKS!

    #1181845

    Hi studiono,

    I tried to use hide instead of fadeout but would still see the shrinking part.
    It will most likely need to modify some core js file do it, since just adjusting the timings doesn’t seem to work (atleast when I tried).
    The workaround I can suggest is disable the shrinking header, so you’ll just have the regular showing header and hidden header on scroll down.

    Best regards,
    Nikko

    #1181909

    I tried disabling the shrinked header and you are right: I love it this way. Thank you very much Nikko you saved my week, not my day :)

    #1181951

    Hi studiono,

    We’re overjoyed to hear that and we’re glad that we could help :D
    I’ll just give credit to where I got the code from https://stackoverflow.com/questions/37505795/hide-header-when-scroll-down-and-show-when-down/#answer-37507343 I just modified it to work on Enfold.
    Thanks for using Enfold and have a great day and weekend!

    Best regards,
    Nikko

Viewing 7 posts - 1 through 7 (of 7 total)
  • The topic ‘Header disappearing and the coming back when scrolling’ is closed to new replies.