fix(Sticky): not work in some cases (#7561)

This commit is contained in:
neverland 2020-11-15 15:14:13 +08:00 committed by GitHub
parent 656909613b
commit 66204dfcf1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,8 +5,7 @@ function isWindow(val: unknown): val is Window {
}
// get nearest scroll element
// http://w3help.org/zh-cn/causes/SD9013
// http://stackoverflow.com/questions/17016740/onscroll-function-is-not-working-for-chrome
// https://github.com/youzan/vant/issues/3823
const overflowScrollReg = /scroll|auto/i;
export function getScroller(el: HTMLElement, root: ScrollElement = window) {
let node = el;
@ -14,24 +13,13 @@ export function getScroller(el: HTMLElement, root: ScrollElement = window) {
while (
node &&
node.tagName !== 'HTML' &&
node.tagName !== 'BODY' &&
node.nodeType === 1 &&
node !== root
) {
const { overflowY } = window.getComputedStyle(node);
if (overflowScrollReg.test(overflowY)) {
if (node.tagName !== 'BODY') {
return node;
}
// see: https://github.com/youzan/vant/issues/3823
const { overflowY: htmlOverflowY } = window.getComputedStyle(
node.parentNode as Element
);
if (overflowScrollReg.test(htmlOverflowY)) {
return node;
}
return node;
}
node = node.parentNode as HTMLElement;
}