Fix for certain websites which don't scroll on their document.documentElement (#193)

- document.documentElement.scrollTop may be zero, but document.body.scrollTop may have the actual scrolling amount
 - main fallback idea taken from https://developer.mozilla.org/en-US/docs/Web/API/Window/scrollX
 - modified as `(document.documentElement || document.body).scrollTop` will incorrectly report zero.
 - version here supported by https://github.com/mochi/mochikit/blob/master/MochiKit/Position.js#L23
This commit is contained in:
Eoghan Murray
2026-04-01 12:00:00 +08:00
committed by GitHub
parent 6a4d9e4c67
commit cd78aaa0fd

View File

@@ -97,8 +97,20 @@ function record<T = eventWithTime>(
data: {
node,
initialOffset: {
left: document.documentElement!.scrollLeft,
top: document.documentElement!.scrollTop,
left: (window.pageXOffset !== undefined) ?
window.pageXOffset : (
document!.documentElement.scrollLeft ||
document!.body!.parentNode.scrollLeft ||
document!.body.scrollLeft ||
0
),
top: (window.pageYOffset !== undefined) ?
window.pageYOffset : (
document!.documentElement.scrollTop ||
document!.body!.parentNode.scrollTop ||
document!.body.scrollTop ||
0
),
},
},
}),