fixed scrollspy
This commit is contained in:
1 parent
0add0ab54c
commit
0dbfb473bf
3 files changed
+11
-7
No files matched your search
@@ -181,7 +181,7 @@ fun DocsPage(
|
||||
scheduled = false
|
||||
try {
|
||||
val heads = toc.mapNotNull { id -> el.querySelector("#${id.id}") as? HTMLHeadingElement }
|
||||
val tops = heads.map { it.getBoundingClientRect().top + window.scrollY }
|
||||
val tops = heads.map { it.getBoundingClientRect().top }
|
||||
val offset = (updateNavbarOffsetVar() + 16).toDouble()
|
||||
val idx = activeIndexForTops(tops, offset)
|
||||
setActiveTocId(if (idx in toc.indices) toc[idx].id else null)
|
||||
|
||||
@@ -1024,11 +1024,15 @@ internal fun normalizePath(path: String): String {
|
||||
// If none are above the offset, returns 0. If list is empty, returns 0.
|
||||
fun activeIndexForTops(tops: List<Double>, offsetPx: Double): Int {
|
||||
if (tops.isEmpty()) return 0
|
||||
var lastAbove = 0
|
||||
for (i in tops.indices) {
|
||||
if (tops[i] - offsetPx > 0.0) return i
|
||||
if (tops[i] <= offsetPx) {
|
||||
lastAbove = i
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
// If all headings are above the offset, select the last one
|
||||
return tops.size - 1
|
||||
return lastAbove
|
||||
}
|
||||
|
||||
fun main() {
|
||||
|
||||
Reference in new issue
Block a user