feat: gfm heading id
This commit is contained in:
@@ -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" });
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user