Skip to content

Commit

Permalink
scroll to header
Browse files Browse the repository at this point in the history
  • Loading branch information
Laurent Denoue committed Nov 29, 2024
1 parent 4b83c22 commit ea3920b
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion code.js
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,11 @@ function createToc(chapters) {
toggleToc()
play(div.start)
let header = Array.from(document.querySelectorAll('.header')).find(h => h.start === div.start)
header?.scrollIntoView()
if (header) {
let topPosition = window.scrollY + header.getBoundingClientRect().top - playercontainer.offsetHeight - 16
console.log('topPosition=',topPosition)
window.scrollTo({left: 0, top: topPosition, behavior: 'smooth'})
}
}
toc.appendChild(div)
}
Expand Down

0 comments on commit ea3920b

Please sign in to comment.