Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1432888

    Hello Enfold team,

    My anchor link positioning doesn’t seem to be working quite right. If I click on the menu item “contact us” from the homepage, it works as expected. However, if I click on this menu link from any other page or from hyperlinks that I’ve created the positioning is off.

    Clicking the menu item “Contact Us” from http://ntechgrate1.sg-host.com works as intended.
    Clicking the menu item “Contact Us” from http://ntechgrate1.sg-host.com/portfolio/ doesn’t scroll far enough.
    Clicking the text “Contact Us” from http://ntechgrate1.sg-host.com/the-franz/ doesn’t scroll far enough.

    Any ideas here?

    Thanks
    -James

    #1432966

    Hey James,

    Thank you for the inquiry.

    The home page loaded correctly on our end, but the subpages didn’t — they showed a broken layout with no styles. Have you installed any third-party compression plugins? Please disable the cache and compression plugins temporarily.

    Best regards,
    Ismael

    #1432970

    Ok, I cleared the cache on the server and disabled all compression and cache plug-ins.

    #1433307

    Hi,
    I added this function in your child theme functions.php to allow your page to fully load, and then scroll to anchor so the height of elements while loading doesn’t change the anchor possession.

    function custom_slow_scroll_script() { 
    ?>
    <script>
    (function($) {
      $('a[href*=#]:not([href=#])').click(function() {
        if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') 
    && location.hostname == this.hostname) {
    
          var target = $(this.hash);
          target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
          if (target.length) {
            $('html,body').animate({
              scrollTop: target.offset().top - 125 //offsets for fixed header
            }, 2000);
            return false;
          }
        }
      });
      //Executed on page load with URL containing an anchor tag.
      if($(location.href.split("#")[1])) {
          var target = $('#'+location.href.split("#")[1]);
          if (target.length) {
            $('html,body').animate({
              scrollTop: target.offset().top - 125 //offset height of header here too.
            }, 2000);
            return false;
          }
        }
    }(jQuery));
    </script>
    <?php
    }
    add_action('wp_footer', 'custom_slow_scroll_script');

    This seems to work in my tests, please clear your browser cache and check.
    Please note that some browsers may require you to clear the history in order to fully clear the cache.

    Best regards,
    Mike

    #1434938

    Mike,

    I am so sorry for my delayed response. I got pulled onto another project and just circled back to this.

    Anyway, your code worked great! Please feel free to close this ticket.

    Thank you so much.
    -James

    #1434943

    Hi,
    Glad we were able to help, if you have any further questions please create a new thread and we will gladly try to help you. Thank you for using Enfold.

    Best regards,
    Mike

Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘Anchor Link Positioning is Off’ is closed to new replies.