Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #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!

    #1346159

    Hey 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,
    Mike

    #1346942

    Hi 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!

    #1346980

    Hi,
    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

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.