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

    Good morning dear support team,

    On the following website I have set an anchor link to the following section several times:

    If you click on the link within a text like this, it jumps somewhere to the end of the desired section: > see screenshot http://neu2.dc-gmbh.com/support/position-textlink.jpg
    For example, an anchor link in the text is located on the HOME page (http://final.dc-gmbh.com/en/) in the left text box (directly below the image slider above) see position in the screenshot: http://neu2 .dc-gmbh.com/support/Anchor-Link-1.jpg

    On the page where the anchor link is located, I placed it here: see screenshot: http://neu2.dc-gmbh.com/support/section-id.jpg (I added a mini color section above because wanted to have a bit of whitespace > so that when I jump here, the heading of the following section doesn’t stick to the top of my screen)

    Why doesn’t this anchor link work? Can you please help me further? Kind regards, Diana

    #1426400

    Hey Diana,
    Thank you for the link to your site and the screenshots, some of them didn’t work, so as I understand this text link on your homepage is not landing correctly for you:
    Enfold_Support_3974.jpeg
    it is meant to land on a empty color section:
    Enfold_Support_3976.jpeg
    when I test it lands correctly, the blue in this screenshot is your empty color section:
    Enfold_Support_3978.jpeg
    I tested with Windows in Chrome & Edge and Mac in Safari & Chrome, and all worked correctly, only Firefox on both Windows & Mac didn’t work correctly, I’m not sure why firefox is having an issue, but to try to adjust for the firefox error I added this code to your functions.php:

    
    function custom_smooth_scroll_to_id_for_firefox_script() { ?>
      <script>
    function slowScrollToAnchor() {
      var urlHash = window.location.hash;
    
      if (urlHash) {
        var target = document.querySelector(urlHash);
        if (target) {
          var targetPosition = target.offsetTop;
          var startPosition = window.pageYOffset;
          var distance = targetPosition - startPosition;
          var duration = 1000;
          var startTime = null;
    
          function scrollAnimation(currentTime) {
            if (startTime === null) startTime = currentTime;
    
            var timeElapsed = currentTime - startTime;
            var scrollY = easeInOutQuad(timeElapsed, startPosition, distance, duration);
            window.scrollTo(0, scrollY);
    
            if (timeElapsed < duration) {
              requestAnimationFrame(scrollAnimation);
            }
          }
          function easeInOutQuad(t, b, c, d) {
            t /= d / 2;
            if (t < 1) return c / 2 * t * t + b;
            t--;
            return -c / 2 * (t * (t - 2) - 1) + b;
          }
    
          requestAnimationFrame(scrollAnimation);
        }
      }
    }
    
    window.addEventListener('load', slowScrollToAnchor);
    </script>
      <?php
    }
    add_action('wp_footer', 'custom_smooth_scroll_to_id_for_firefox_script', 99);

    and after clearing your site cacke and my browser caches for all of my test browsers the anchor link is now correct, even in Firefox. Most of my tests landed correctly even on firefox, but in one case on firefox the script scrolled the page backwards to land in the land place. So the script shows to correct the issue.
    If you want to adjust the one second delay you can change var duration = 1000; to a higher or lower number 1000 equals one second, it seem to work good just the way it is.

    BTW – your Header Footer Code Manager plugin don’t seem to allow PHP snippets, so if you are not going to use a child theme I recommend the WPcode plugin this plugin supports PHP code snippets, JavaScript code snippets, & CSS code snippets.

    Best regards,
    Mike

    #1426422

    It works fine for me in Firefox now that Mike has made some changes.
    But why make life so difficult for yourself? A very slim plugin like Page Scroll to ID does this very elegantly. For example, you can not only specify an offset, but even an offset scroll position in the form of a selector: #header. This makes perfect sense for our shrinking header. But what I really like is the ability to navigate to an anchor on another page. This can be set so that the page opens at the top and then scrolls to the anchor after an (adjustable) delay.

    #1426425

    Hi,

    Thanks for helping out @guenni007 :-)

    Best regards,
    Rikard

    #1426938

    Thanks for the help. Everything fits perfectly now!
    And thanks for the implementation and the alternative tips. Really great support!

    #1426950

    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 doesn t work’ is closed to new replies.