Something went wrong. Try again.
Fork of Chiri for Astro for my blog forked from quillmatiq.com/augment
Something went wrong. Try again.
1.3 kB · 43 lines
Astro
at main
1234567891011121314151617181920212223242526272829303132333435363738394041424344<script> function bindFootnoteEvents() { const footnoteLinks = document.querySelectorAll('[data-footnote-ref], [data-footnote-backref]')
footnoteLinks.forEach((link) => { // Skip if already bound if (link.dataset.footnoteBound) return link.dataset.footnoteBound = 'true'
link.addEventListener('click', (e) => { e.preventDefault() const href = link.getAttribute('href') if (!href) return
const target = document.querySelector(href) if (!target) return
// Use fixed offset of 128px const offset = 128
const targetPosition = target.getBoundingClientRect().top + window.scrollY - offset
window.scrollTo({ top: targetPosition })
// Highlight effect const highlightTarget = target.closest('cite') || target.closest('sup') || target highlightTarget.classList.add('footnote-highlight') highlightTarget.addEventListener( 'animationend', () => { highlightTarget.classList.remove('footnote-highlight') }, { once: true } ) }) }) }
// Use only astro:page-load as it fires on initial load and navigation document.addEventListener('astro:page-load', bindFootnoteEvents)</script>