-
AuthorPosts
-
March 26, 2022 at 8:55 pm #1346151
I was wondering if there was a way to make only the upper header (with the phone number) stick on scroll?
Currently, when we scroll down the whole header moves up and we don’t want the full header to stick!
March 26, 2022 at 10:32 pm #1346159Hey Michael,
Thanks for the link to your site, currently it looks like your header is sticky so you will disable that and add this code to the end of your functions.php:function sticky_header_meta() { ?> <script> (function($){ $(function() { var scroll_start = 0; var startchange = $('#header_meta'); var offset = startchange.offset(); if (startchange.length){ $(document).scroll(function() { scroll_start = $(this).scrollTop(); if(scroll_start > offset.top) { document.getElementById('header_meta').classList.add('sticky-top'); } else { document.getElementById('header_meta').classList.remove('sticky-top'); } }); } }); })(jQuery); </script> <?php } add_action('wp_footer', 'sticky_header_meta');
and this code to your Quick CSS:
#header_meta.sticky-top { position:fixed!important; top:0!important; z-index:10000!important; width: 100%; }
Then clear your browser cache and any cache plugin, and check.
Best regards,
MikeApril 2, 2022 at 1:42 am #1346942Hi Mike,
You know what your right! I should have mentioned that the upper header (with phone number) and main header (with page tabs) does work as I want it to on desktop mode. However, on the mobile mode I was hoping to have only the upper header stick (phone number) when i scroll down. Will the code you provided make this happen? Thanks for your help!
April 2, 2022 at 1:25 pm #1346980Hi,
The script above should work correctly for mobile only, just use this css instead of the css above:@media only screen and (max-width: 767px) { #header_meta.sticky-top { position:fixed!important; top:0!important; z-index:10000!important; width: 100%; } }
Then clear your browser cache and check.
Best regards,
Mike -
AuthorPosts
- You must be logged in to reply to this topic.