Skip to content

Commit

Permalink
fix(article): footnote reference does not work
Browse files Browse the repository at this point in the history
closes #632
  • Loading branch information
CaiJimmy committed Jul 28, 2022
1 parent b02569a commit 655b510
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions assets/ts/smoothAnchors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@ function setupSmoothAnchors() {
aElement.addEventListener("click", clickEvent => {
clickEvent.preventDefault();

let 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.
let target = document.getElementById(targetId.replace(":", "\\:")) as HTMLElement;
const targetId = aElement.getAttribute("href").substring(1),
target = document.getElementById(targetId) as HTMLElement,
offset = target.getBoundingClientRect().top - document.documentElement.getBoundingClientRect().top;

window.history.pushState({}, "", aElement.getAttribute("href"));
scrollTo({ top: target.offsetTop, behavior: "smooth" });
scrollTo({
top: offset,
behavior: "smooth"
});
});
});
}
Expand Down

0 comments on commit 655b510

Please sign in to comment.