forked from
quillmatiq.com/augment
Fork of Chiri for Astro for my blog
1<script>
2 function bindFootnoteEvents() {
3 const footnoteLinks = document.querySelectorAll('[data-footnote-ref], [data-footnote-backref]')
4
5 footnoteLinks.forEach((link) => {
6 link.addEventListener('click', (e) => {
7 e.preventDefault()
8 const href = link.getAttribute('href')
9 if (!href) return
10
11 const target = document.querySelector(href)
12 if (!target) return
13
14 // Use fixed offset of 128px
15 const offset = 128
16
17 const targetPosition = target.getBoundingClientRect().top + window.scrollY - offset
18
19 window.scrollTo({
20 top: targetPosition
21 })
22 })
23 })
24 }
25
26 document.addEventListener('astro:page-load', () => {
27 bindFootnoteEvents()
28 })
29
30 document.addEventListener('DOMContentLoaded', () => {
31 bindFootnoteEvents()
32 })
33</script>