Tagged: anchor
-
AuthorPosts
-
April 22, 2020 at 11:01 am #1206133
Hi there,
On the page of our client, we used anchor links.
If you are in Chrome and on the Homepage while using the menu, the anchor link on the new page is above the view, when the page is loaded.
Below are some links and infos, do you have any idea why this is happening?Thank you very much,
ElbnetzApril 26, 2020 at 3:36 pm #1207271Hey ksalewski,
Sorry for the late reply, it looks like you are getting an early errorUncaught TypeError: Cannot read property 'innerHTML' of null
from:jQuery(window).load(function() { var el = document.querySelector('.avia-caption-title'); el.outerHTML = '<h1 class="avia-caption-title ">' + el.innerHTML + '</h1>'; });
This looks like a custom script, perhaps in your functions.php? Please try removing it and clearing your cache then test your menu item.
Best regards,
MikeApril 27, 2020 at 8:35 am #1207447Hi There,
Thank you for the reply! I removed the script and cleared the cache, sadly the problem is still there.
We only discovered it shortly after the update to WordPress 5.4 was made.Many thanks,
ElbnetzApril 27, 2020 at 1:36 pm #1207506Hi,
I believe that the page is going to the anchor but the page is not fully loaded yet, so when the page is finished loading the position of the scroll is not correct. This seems to help.
Try adding this code to the end of your functions.php file in Appearance > Editor:function custom_scroll_script(){ ?> <script> (function($) { $('a[href*="#"]:not([href="#"])').click(function() { var target = $(this.hash); $('html,body').stop().animate({ scrollTop: target.offset().top - 90 }, 'linear'); }); if (location.hash){ var id = $(location.hash); } $(window).load(function() { if (location.hash){ $('html,body').animate({scrollTop: id.offset().top -90}, 'linear') }; }); })(jQuery); </script> <?php } add_action('wp_footer', 'custom_scroll_script');
Please add this function and clear your browser cache and check.
Best regards,
MikeApril 27, 2020 at 1:49 pm #1207508Hi Mike,
Thank you very much for the help! This worked for us!
Best regards,
ElbnetzApril 28, 2020 at 2:13 am #1207673Hi,
I’m glad this was resolved. If you need additional help, please let us know here in the forums.
Best regards,
Jordan Shannon -
AuthorPosts
- The topic ‘Anchor jumps too far in Chrome’ is closed to new replies.