Add smooth scrolling to TOC
This commit is contained in:
@@ -15,6 +15,20 @@
|
||||
lnk.href=`#${tag.id}`
|
||||
lnk.className = 'b1-no-underline'
|
||||
lnk.innerHTML = `<span class="mr-1">${"#".repeat(depth)}</span>${tag.innerHTML}`
|
||||
|
||||
// Add smooth scroll with offset
|
||||
lnk.addEventListener('click', (e) => {
|
||||
e.preventDefault()
|
||||
const target = document.getElementById(tag.id)
|
||||
if (target) {
|
||||
const offset = 20 // pixels from top
|
||||
const targetPosition = target.getBoundingClientRect().top + window.pageYOffset - offset
|
||||
window.scrollTo({
|
||||
top: targetPosition,
|
||||
behavior: 'smooth'
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
let li = document.createElement('li')
|
||||
li.className = 'line-clamp-1'
|
||||
|
||||
Reference in New Issue
Block a user