Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #1487500

    HI
    on the page below I have an image with 2 hotspots labeled Berlin and Copenhagen.
    I have added an anchor link to the hotspot as well as to the text.
    The text link works, but it jumps to the section instead of smooth scrolling.
    I tested with the Berlin link at the top of the page which scrolls properly.
    Neither hotspot “spot” has the anchor link that I added – isn’t it supposed to link from the spot?
    I would like both the spot and the text to have anchor links that scroll smoothly if possible.
    Can you help me with this?
    thanks
    Nancy

    #1487502

    Hey Munford,
    I believe that we were working on the page at the same time, as it changed. Nonetheless, try adding this code to the end of your child theme functions.php file in Appearance ▸ Editor:

    function hotspot_smooth_scroll() { ?>
      <script>
    document.addEventListener('DOMContentLoaded', function () {
      document.querySelectorAll('.av-image-hotspot .avia-tooltip .inner_tooltip a[href^="#"]').forEach(function(anchor) {
        anchor.addEventListener('click', function(e) {
          // Prevent default jump
          e.preventDefault();
          const targetID = this.getAttribute('href').substring(1);
          const targetElement = document.getElementById(targetID);
    
          if (targetElement) {
            targetElement.scrollIntoView({
              behavior: 'smooth'
            });
    
            // Optionally update URL hash
            history.pushState(null, null, '#' + targetID);
          }
        });
      });
    });
    </script>
      <?php
    }
    add_action( 'wp_footer', 'hotspot_smooth_scroll', 99 );

    Best regards,
    Mike

    #1487503

    ah yes that’s what was happening.
    I think it’s fixed now – did you add that or is it just working?
    I saw that the link was working and scrolling correctly from the “spot” so had taken the links off the text.
    I added that code and then added it back on the “Berlin” tooltip text but it jumps instead of smooth scrolliing still, even though the spot scrolls smoothly. Purged the cache…any ideas?
    Nancy

    • This reply was modified 20 hours, 45 minutes ago by Munford.
    #1487506

    Hi,
    PS, Please ensure to copy the code from the forum and not an email notification so the symbols are not converted.

    Best regards,
    Mike

    #1487521

    Yes, I copied the right code but the text links are not smooth scrolling.
    I am now seeing an issue if I use the transparent header that the anchor link lands too high, and the header is not transparent on mobile.
    Can you help with that?
    thanks
    Nancy

    • This reply was modified 16 minutes ago by Munford.
Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.