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
This commit is contained in:
Nick Spreitzer 2020-10-30 12:09:44 -05:00 committed by GitHub
parent 0a7a540761
commit 55107fcfc2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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"
});
});