Only smooth scrolling when clicking on toc
This commit is contained in:
parent
108d150d98
commit
6dd1780925
|
@ -519,7 +519,6 @@ const { currentTheme } = Astro.locals;
|
||||||
}
|
}
|
||||||
|
|
||||||
* {
|
* {
|
||||||
scroll-behavior: smooth;
|
|
||||||
scrollbar-width: thin;
|
scrollbar-width: thin;
|
||||||
scrollbar-color: var(--color-base-650) transparent;
|
scrollbar-color: var(--color-base-650) transparent;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ const { entry } = Astro.props;
|
||||||
{/* ------------------------------------------- HTML ------------------------------------------- */}
|
{/* ------------------------------------------- HTML ------------------------------------------- */}
|
||||||
|
|
||||||
<li data-prefix={entry.prefix}>
|
<li data-prefix={entry.prefix}>
|
||||||
<a href={`#${entry.prefix}`} class="pressable-link">{entry.title}</a>
|
<a href={`#${entry.prefix}`} class="pressable-link table-of-content-item">{entry.title}</a>
|
||||||
{
|
{
|
||||||
entry.children.length > 0 && (
|
entry.children.length > 0 && (
|
||||||
<ol>
|
<ol>
|
||||||
|
@ -44,3 +44,19 @@ const { entry } = Astro.props;
|
||||||
line-height: 125%;
|
line-height: 125%;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
{/* ------------------------------------------- JS --------------------------------------------- */}
|
||||||
|
|
||||||
|
<script>
|
||||||
|
document.querySelectorAll(".table-of-content-item").forEach((element) => {
|
||||||
|
const href = element.getAttribute("href")?.substring(1);
|
||||||
|
if (!href) return;
|
||||||
|
const heading = document.getElementById(href);
|
||||||
|
if (!heading) return;
|
||||||
|
|
||||||
|
element.addEventListener("click", (event) => {
|
||||||
|
heading.scrollIntoView({ behavior: "smooth" });
|
||||||
|
event.preventDefault();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
Loading…
Reference in New Issue