mirror of
https://github.com/CaiJimmy/hugo-theme-stack.git
synced 2024-11-23 10:21:46 +01:00
fix(article): footnote reference does not work
closes https://github.com/CaiJimmy/hugo-theme-stack/issues/632
This commit is contained in:
parent
b02569add9
commit
655b5102c4
1 changed files with 7 additions and 4 deletions
|
@ -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"
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue