Merge branch 'master' into patch-1

This commit is contained in:
Jimmy Cai 2022-07-31 12:37:41 +02:00 committed by GitHub
commit 27f4d8441b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -21,12 +21,15 @@ function setupSmoothAnchors() {
aElement.addEventListener("click", clickEvent => { aElement.addEventListener("click", clickEvent => {
clickEvent.preventDefault(); clickEvent.preventDefault();
let targetId = aElement.getAttribute("href").substring(1); const targetId = aElement.getAttribute("href").substring(1),
// The replace done on ':' is here for footnotes, as this character would otherwise interfere when used as a CSS selector. target = document.getElementById(targetId) as HTMLElement,
let target = document.getElementById(targetId.replace(":", "\\:")) as HTMLElement; offset = target.getBoundingClientRect().top - document.documentElement.getBoundingClientRect().top;
window.history.pushState({}, "", aElement.getAttribute("href")); window.history.pushState({}, "", aElement.getAttribute("href"));
scrollTo({ top: target.offsetTop, behavior: "smooth" }); scrollTo({
top: offset,
behavior: "smooth"
});
}); });
}); });
} }