-
AuthorPosts
-
February 3, 2020 at 7:01 pm #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!
February 4, 2020 at 9:21 am #1181192any idea about this?
February 5, 2020 at 10:37 am #1181680Hi 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,
NikkoFebruary 5, 2020 at 10:54 am #1181701WOW 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!
February 5, 2020 at 5:30 pm #1181845Hi 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,
NikkoFebruary 5, 2020 at 10:23 pm #1181909I 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 :)
February 6, 2020 at 4:26 am #1181951Hi 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 -
AuthorPosts
- The topic ‘Header disappearing and the coming back when scrolling’ is closed to new replies.