Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/CaiJimmy/hugo-theme-stack.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJimmy Cai <github@jimmycai.com>2022-07-28 19:48:37 +0300
committerJimmy Cai <github@jimmycai.com>2022-07-28 19:48:37 +0300
commit655b5102c4caffb76f38c68d353b992de036b007 (patch)
tree4c76233b73624cc6693b5b28c23618c67f80e7f4
parentb02569add95ceb08ccddba01fb3e810b41db1ce6 (diff)
fix(article): footnote reference does not work
closes https://github.com/CaiJimmy/hugo-theme-stack/issues/632
-rw-r--r--assets/ts/smoothAnchors.ts11
1 files changed, 7 insertions, 4 deletions
diff --git a/assets/ts/smoothAnchors.ts b/assets/ts/smoothAnchors.ts
index 379eb39..46a4a03 100644
--- a/assets/ts/smoothAnchors.ts
+++ b/assets/ts/smoothAnchors.ts
@@ -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"
+ });
});
});
}