feat: gfm heading id

This commit is contained in:
2026-03-02 13:43:10 +08:00
parent df990d4453
commit 13007c8fa4
4 changed files with 27 additions and 2 deletions
+5 -2
View File
@@ -87,11 +87,14 @@ export const HeadingNode: Component<{
const handleClick = (e: MouseEvent) => {
e.preventDefault();
navigate(href);
// 滚动到目标元素
// 滚动到目标元素,考虑导航栏高度偏移
requestAnimationFrame(() => {
const element = document.getElementById(anchor);
if (element) {
element.scrollIntoView({ behavior: "smooth", block: "start" });
const navBarHeight = 80;
const elementPosition = element.getBoundingClientRect().top;
const offsetPosition = window.scrollY + elementPosition - navBarHeight;
window.scrollTo({ top: offsetPosition, behavior: "smooth" });
}
});
};