From 55107fcfc2d79ee0fd713d33f9775f0af842487f Mon Sep 17 00:00:00 2001 From: Nick Spreitzer Date: Fri, 30 Oct 2020 12:09:44 -0500 Subject: [PATCH] footer: Fix broken anchor link scrolling (#64) fixes: Footnotes anchor link hrefs such as `#fn:1` fixes: ToC anchors failing with hrefs having numbers. based-on: https://stackoverflow.com/a/51396346/300212 --- layouts/partials/footer.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/layouts/partials/footer.html b/layouts/partials/footer.html index b94ace04..f3baf823 100644 --- a/layouts/partials/footer.html +++ b/layouts/partials/footer.html @@ -30,8 +30,8 @@ document.querySelectorAll('a[href^="#"]').forEach(anchor => { anchor.addEventListener("click", function (e) { e.preventDefault(); - - document.querySelector(this.getAttribute("href")).scrollIntoView({ + var id = this.getAttribute("href").substr(1); + document.querySelector(`[id='${id}']`).scrollIntoView({ behavior: "smooth" }); });