修复当文章目录为数字开头时无法跳转的问题

This commit is contained in:
lonzzi 2022-05-08 19:04:16 +08:00
parent c1fcec95a6
commit 35390c6148

View File

@ -23,7 +23,7 @@ function setupSmoothAnchors() {
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.querySelector(`#${targetId.replace(":", "\\:")}`) as HTMLElement;
let target = document.getElementById(targetId.replace(":", "\\:")) as HTMLElement;
window.history.pushState({}, "", aElement.getAttribute("href"));
scrollTo({ top: target.offsetTop, behavior: "smooth" });