Sticky header covers heading on anchor links

Hi there,

I’ve been researching for a solution to work around the problem that the sticky header covers for some of the content when using anchor links.

I’ve found two solutions: adding padding to each anchor with css https://theme.co/apex/forum/t/anchor-link-title-hidden-by-sticky-header-in-x-pro/17983/2
or adding padding directly to sections and even it out adding same negative margin https://theme.co/apex/forum/t/sticky-header-bar-in-the-way-of-links/15074

However, I have between 7-10 anchors on my site and am looking for a solution that could easily be applied to all of them - would that be possible?

Thanks.

Hi There,

Thanks for asking!

Can you please send us your website URL so that we can give you a proper solution.
The post you have share might have different case than yours.

Thanks

Hi there,

Yes ofc. :slight_smile: https://openframe.org

Hi There,

Can you please confirm in which page you have the issue, seems I can’t replicate the issue in your site.
Please provide a screenshot and the page URL.

Thanks

Hi there,

This page holds 6 anchors: https://openframe.org/funktioner/

Please see attached screenshot for example of how it looks - you cannot see the heading of the section, which in this case is a function being described, hence it’s quite relevant for the visitor to see.

This page also has an anchor: https://openframe.org/om-frame/

Hey @KnowledgeWorker,

Sorry for the confusion. Pro does not currently have a feature that could offset a sticky Pro built header and there’s no temporary workaround for this. Our development team is aware of this limitation though and this might be supported in one of the succeeding releases. Please stay tuned for updates.

Thanks.

Hi Christian,

Thanks for your update on the problem. Solved it with CSS for now.

Glad that you figure it out!

Thanks

I’m having the same issue. If you don’t mind, how did you solve it using CSS? I’m currently fixing it in some places by physically putting the anchor point in a higher up element than it belongs … but this doesn’t work universally. For example, you can click the “Top” link on the floating menu at right and the top remains partially hidden by my sticky header.

Hi @lancesalyers,

Thanks for writing in! As a work around you can add the following code in the Theme Options > JS:

jQuery(document).ready(function($) {

  var $body                = $('body');
  var bodyHeight           = $body.outerHeight();
  var adminbarHeight       = $('#wpadminbar').outerHeight();
  var navbarFixedTopHeight = $('.x-masthead .x-bar-fixed').outerHeight();
  var locHref              = location.href;
  var locHashIndex         = locHref.indexOf('#');
  var locHash              = locHref.substr(locHashIndex);
  var dragging             = false;
  
  $body.on('touchmove', function() {
      dragging = true;
  } );
  
  $body.on('touchstart', function() {
      dragging = false;
  } );


  //
  // Calculate the offset height for various elements and remove it from
  // the element's top offset so that fixed elements don't cover it up.
  //

  function animateOffset( element, ms, easing ) {
    $('html, body').animate({
      scrollTop: $(element).offset().top - adminbarHeight - navbarFixedTopHeight + 1
    }, ms, easing);
  }


  //
  // Page load offset (if necessary).
  //

  $(window).load(function() {
    if ( locHashIndex !== -1 && $(locHash).length ) {
      animateOffset(locHash, 1, 'linear');
    }
  });


  //
  // Scroll trigger.
  //

  $('a[href*="#"]').off('touchend click').on('touchend click', function(e) {
      console.log($('.hm1.x-bar-fixed').outerHeight());
    href        = $(this).attr('href');
    notComments = href.indexOf('#comments') === -1;
    if ( href !== '#' && notComments ) {
      var theId = href.split('#').pop();
      var $el   = $('#' + theId);
      if ( $el.length > 0 ) {
        e.preventDefault();
        
        if (dragging) {
            return;
        }
		
		if( $('.x-anchor-toggle').hasClass('x-active') ) {
			$('.x-anchor-toggle').click();
		}
        
        animateOffset($el, 850, 'xEaseInOutExpo');
      }
    }
  });
});

This should fix the offset issue, you can then remove your manual spacing from the sections.

Don’t forget to clear your browser’s cache after adding the code. Let us know how this goes!

Thanks! I wasn’t expecting a remedy. I copied it into my Theme Options > JS, but I don’t see any difference.

Hi @lancesalyers,

I have tried your setup and it is working well both your contact form and services link.

https://www.screencast.com/t/RGmLIdE5AeGO

Try to clear you site and browser cache before checking again.

Let us know how it goes.

Thanks.

The problem I’m seeing is on the “IDEAS” page. When the user navigates down the page, using the “Top” link on the floating menu at right results in this:

Hi,

Please change the js code to this.

jQuery(document).ready(function($) {

  var $body                = $('body');
  var bodyHeight           = $body.outerHeight();
  var adminbarHeight       = $('#wpadminbar').outerHeight();
  var navbarFixedTopHeight = 60;
  var locHref              = location.href;
  var locHashIndex         = locHref.indexOf('#');
  var locHash              = locHref.substr(locHashIndex);
  var dragging             = false;
  
  $body.on('touchmove', function() {
      dragging = true;
  } );
  
  $body.on('touchstart', function() {
      dragging = false;
  } );


  //
  // Calculate the offset height for various elements and remove it from
  // the element's top offset so that fixed elements don't cover it up.
  //

  function animateOffset( element, ms, easing ) {
    $('html, body').animate({
      scrollTop: $(element).offset().top - adminbarHeight - navbarFixedTopHeight + 1
    }, ms, easing);
  }


  //
  // Page load offset (if necessary).
  //

  $(window).load(function() {
    if ( locHashIndex !== -1 && $(locHash).length ) {
      animateOffset(locHash, 1, 'linear');
    }
  });


  //
  // Scroll trigger.
  //

  $('a[href*="#"]').off('touchend click').on('touchend click', function(e) {
      console.log($('.hm1.x-bar-fixed').outerHeight());
    href        = $(this).attr('href');
    notComments = href.indexOf('#comments') === -1;
    if ( href !== '#' && notComments ) {
      var theId = href.split('#').pop();
      var $el   = $('#' + theId);
      if ( $el.length > 0 ) {
        e.preventDefault();
        
        if (dragging) {
            return;
        }
        
        if( $('.x-anchor-toggle').hasClass('x-active') ) {
            $('.x-anchor-toggle').click();
        }
        
        animateOffset($el, 850, 'xEaseInOutExpo');
      }
    }
  });
});

Hope that helps

NAILED IT! Thanks Paul!

We are delighted to assist you with this.

Cheers!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.