Fixed invalid anchor list offset for hidden anchors

This commit is contained in:
squidfunk 2020-02-18 17:07:20 +01:00
parent dee75ccfbb
commit d4f5b1377c

View File

@ -132,9 +132,18 @@ export function watchAnchorList(
break break
} }
} }
/* If the current anchor is hidden, continue with its parent */
let offset = target.offsetTop
while (!offset && target.parentElement) {
target = target.parentElement
offset = target.offsetTop
}
/* Map reversed anchor path to vertical offset */
return index.set( return index.set(
reverse(path = [...path, anchor]), reverse(path = [...path, anchor]),
target.offsetTop offset
) )
}, new Map<HTMLAnchorElement[], number>()) }, new Map<HTMLAnchorElement[], number>())
}), }),