mirror of
https://github.com/pengzhanbo/vuepress-theme-plume.git
synced 2026-04-23 10:58:13 +08:00
This commit is contained in:
parent
6e1992f811
commit
00a858761c
@ -187,7 +187,7 @@ export function useActiveAnchor(container: Ref<HTMLElement | null>, marker: Ref<
|
||||
if (!isAsideEnabled.value)
|
||||
return
|
||||
|
||||
const scrollY = window.scrollY
|
||||
const scrollY = Math.round(window.scrollY)
|
||||
const innerHeight = window.innerHeight
|
||||
const offsetHeight = document.body.offsetHeight
|
||||
const isBottom = Math.abs(scrollY + innerHeight - offsetHeight) < 1
|
||||
@ -222,7 +222,7 @@ export function useActiveAnchor(container: Ref<HTMLElement | null>, marker: Ref<
|
||||
// find the last header above the top of viewport
|
||||
let activeLink: string | null = null
|
||||
for (const { link, top } of headers) {
|
||||
if (top > scrollY + 88)
|
||||
if (top > scrollY + 92)
|
||||
break
|
||||
|
||||
activeLink = link
|
||||
@ -284,18 +284,14 @@ export function useActiveAnchor(container: Ref<HTMLElement | null>, marker: Ref<
|
||||
|
||||
function getAbsoluteTop(element: HTMLElement): number {
|
||||
let offsetTop = 0
|
||||
while (element !== document.body) {
|
||||
if (element === null) {
|
||||
// child element is:
|
||||
// - not attached to the DOM (display: none)
|
||||
// - set to fixed position (not scrollable)
|
||||
// - body or html element (null offsetParent)
|
||||
return Number.NaN
|
||||
while (element && element !== document.body) {
|
||||
if (window.getComputedStyle(element).position === 'fixed') {
|
||||
return element.offsetTop
|
||||
}
|
||||
offsetTop += element.offsetTop
|
||||
element = element.offsetParent as HTMLElement
|
||||
}
|
||||
return offsetTop
|
||||
return element ? offsetTop : Number.NaN
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user