Skip to content

Commit d491504

Browse files
committed
Add smooth scrolling to whole site with CSS
1 parent dacc4ec commit d491504

File tree

2 files changed

+1
-14
lines changed

2 files changed

+1
-14
lines changed

src/components/TableOfContents.astro

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,6 @@ const toc = generateToc(headings)
5353
</nav>
5454
</details>
5555

56-
<script>
57-
document.querySelectorAll('a[href^="#"]').forEach((anchor) => {
58-
anchor.addEventListener('click', function (e) {
59-
e.preventDefault()
60-
const href = anchor.getAttribute('href')
61-
if (!href) return
62-
const id = href.startsWith('#') ? href.slice(1) : href
63-
document.getElementById(id)?.scrollIntoView({
64-
behavior: 'smooth',
65-
})
66-
})
67-
})
68-
</script>
69-
7056
<style>
7157
details[open] summary:before {
7258
transform: rotate(90deg);

src/styles/global.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ html {
4646
scrollbar-color: color-mix(in oklab, var(--theme-accent) 30%, transparent) transparent !important;
4747
/* Prevents layout from jumping when opening theme select or search dialog menus */
4848
scrollbar-gutter: stable;
49+
scroll-behavior: smooth;
4950
}
5051

5152
body {

0 commit comments

Comments
 (0)