mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-05-22 14:39:16 +08:00
fix(Sticky): not work in some cases (#7561)
This commit is contained in:
parent
656909613b
commit
66204dfcf1
@ -5,8 +5,7 @@ function isWindow(val: unknown): val is Window {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get nearest scroll element
|
// get nearest scroll element
|
||||||
// http://w3help.org/zh-cn/causes/SD9013
|
// https://github.com/youzan/vant/issues/3823
|
||||||
// http://stackoverflow.com/questions/17016740/onscroll-function-is-not-working-for-chrome
|
|
||||||
const overflowScrollReg = /scroll|auto/i;
|
const overflowScrollReg = /scroll|auto/i;
|
||||||
export function getScroller(el: HTMLElement, root: ScrollElement = window) {
|
export function getScroller(el: HTMLElement, root: ScrollElement = window) {
|
||||||
let node = el;
|
let node = el;
|
||||||
@ -14,25 +13,14 @@ export function getScroller(el: HTMLElement, root: ScrollElement = window) {
|
|||||||
while (
|
while (
|
||||||
node &&
|
node &&
|
||||||
node.tagName !== 'HTML' &&
|
node.tagName !== 'HTML' &&
|
||||||
|
node.tagName !== 'BODY' &&
|
||||||
node.nodeType === 1 &&
|
node.nodeType === 1 &&
|
||||||
node !== root
|
node !== root
|
||||||
) {
|
) {
|
||||||
const { overflowY } = window.getComputedStyle(node);
|
const { overflowY } = window.getComputedStyle(node);
|
||||||
|
|
||||||
if (overflowScrollReg.test(overflowY)) {
|
if (overflowScrollReg.test(overflowY)) {
|
||||||
if (node.tagName !== 'BODY') {
|
|
||||||
return node;
|
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
node = node.parentNode as HTMLElement;
|
node = node.parentNode as HTMLElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user