Anchor Links scrolling to far

Hello

On my site I’m using anchor links on some pages but when I click the anchor link on the same page it scrolls too far down note when I come from a different page it scrolls the right amount. I think is due to having a fixed top bar as it only occurs on desktop view.

Hi Patrick,

To fix it, you can add the code below in Theme Options > JS

jQuery(document).ready(function($) {
 var adminbarHeight       = $('#wpadminbar').outerHeight();
  var navbarFixedTopHeight = $('.x-navbar-fixed-top-active .x-navbar').outerHeight();
  $('a[href*="#"]').off('touchend click').on('touchend click', function(e) {
	 e.preventDefault();
	var href = $(this).attr("href");
	var hash = href.substr(href.indexOf("#"));

    $('html, body').animate({
        scrollTop: $(hash).offset().top  - adminbarHeight - navbarFixedTopHeight 
    }, 650);
    return false;
});
});

Hope that helps.

Thank you

That works.

You’re welcome! :slight_smile:

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