
Tagged: hotspot, smooth scroll
-
AuthorPosts
-
August 2, 2025 at 3:42 pm #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
NancyAugust 2, 2025 at 5:29 pm #1487502Hey 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,
MikeAugust 2, 2025 at 5:32 pm #1487503ah 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 3 weeks ago by
Munford.
August 2, 2025 at 5:40 pm #1487506Hi,
PS, Please ensure to copy the code from the forum and not an email notification so the symbols are not converted.Best regards,
MikeAugust 3, 2025 at 2:00 pm #1487521Yes, 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 3 weeks ago by
Munford.
August 3, 2025 at 2:29 pm #1487523Hi,
They smooth scroll when I check?
Please keep each thread to one topic, feel free to open multiple threads.Best regards,
MikeAugust 3, 2025 at 5:10 pm #1487526when I click on the spot it is smooth, but the text link jumps to the section instead.
They also land at different heights on the page – see below.
I know this is due to the sticky header but don’t know how to fix it.
thanks for your help
Nancy-
This reply was modified 2 weeks, 6 days ago by
Munford.
August 4, 2025 at 7:06 am #1487539Hi,
We adjusted the scroll position a bit.
const offsetPosition = elementPosition + 142;
Please try it again:
function av_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) { e.preventDefault(); const targetID = this.getAttribute('href').substring(1); const targetElement = document.getElementById(targetID); if (targetElement) { const elementPosition = targetElement.getBoundingClientRect().top + window.pageYOffset; const offsetPosition = elementPosition + 142; window.scrollTo({ top: offsetPosition, behavior: 'smooth' }); history.pushState(null, null, '#' + targetID); } }); }); }); </script> <?php } add_action( 'wp_footer', 'av_hotspot_smooth_scroll', 99 );
Adjust the value 142 as needed.
Best regards,
IsmaelAugust 4, 2025 at 11:17 am #1487549that changed the link position on the text but not on the hotspot itself, and the text link still jumps to the section…
-
This reply was modified 2 weeks, 6 days ago by
Munford.
August 5, 2025 at 6:55 am #1487585Hi,
Please looks for this line:
document.querySelectorAll('.av-image-hotspot .avia-tooltip .inner_tooltip a[href^="#"]').forEach(function(anchor) {
Replace it with:
document.querySelectorAll('.av-image-hotspot .avia-tooltip .inner_tooltip a[href^="#"], .av-image-hotspot .av-image-hotspot_inner').forEach(function(anchor) {
Let us know the result.
Best regards,
Ismael -
This reply was modified 3 weeks ago by
-
AuthorPosts
- You must be logged in to reply to this topic.