Open VincentTam opened 5 years ago
I got the same problem ... the element specified in the URL hash was hidden by the navigation bar. The problem can be solved by writing the following in a script file such as main.js.
document.addEventListener('DOMContentLoaded', function(){
$(window).on("load hashchange", function(e){
if(("" == window.location.hash) || (0 == $(".navbar").length)) return;
const navbarH = $(".navbar").height();
const adjustT = $(window.location.hash.replace(":", "\\:"))[0].getBoundingClientRect().top - navbarH;
if(0 > adjustT) $("html,body").animate({scrollTop:("-=" + Math.abs(adjustT))}, 300);
});
});
And also, there is another way to solve it with css. Take a look below.
https://ayaco.gitlab.io/zerogravity/post/2021-11-14-start-blog-for-free8/
To reproduce this (diff output attached below):
exampleSite/content
(say, Photoswipe Gallery Sample), mark some words in first paragraph with<span id="test">Beautiful Hugo</span>
.<a href="#test">Note</a>
.cd exampleSite; hugo server --themesDir=../..
After I clicked on the anchor below, which points to the start of the first paragraph, the anchor sends me to the anchor target, which is covered by the navbar on the top. This happens on Desktop browsers. I've tested this with Google Chrome on mobile, and I didn't observe this on my phone.