mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-05-07 02:51:10 +08:00
fix: 修正getScrollParent逻辑 (#141)
* Create const.ts 错别字 * docs:修改注释中错别字 * fix: 修正getScrollParent逻辑
This commit is contained in:
parent
b751621488
commit
f72b8c7614
@ -118,15 +118,17 @@ export const getMode = (el: HTMLElement): Mode => {
|
|||||||
|
|
||||||
export const getScrollParent = (element: HTMLElement, includeHidden = false): HTMLElement | null => {
|
export const getScrollParent = (element: HTMLElement, includeHidden = false): HTMLElement | null => {
|
||||||
let style = getComputedStyle(element);
|
let style = getComputedStyle(element);
|
||||||
|
const excludeStaticParent = style.position === 'absolute';
|
||||||
const overflowRegex = includeHidden ? /(auto|scroll|hidden)/ : /(auto|scroll)/;
|
const overflowRegex = includeHidden ? /(auto|scroll|hidden)/ : /(auto|scroll)/;
|
||||||
|
|
||||||
if (isFixed(element)) return null;
|
if (style.position === 'fixed') return null;
|
||||||
|
|
||||||
for (let parent = element; parent.parentElement; ) {
|
for (let parent = element; parent.parentElement; ) {
|
||||||
parent = parent.parentElement;
|
parent = parent.parentElement;
|
||||||
style = getComputedStyle(parent);
|
style = getComputedStyle(parent);
|
||||||
if (isAbsolute(element) && isStatic(element)) {
|
|
||||||
continue;
|
if (excludeStaticParent && style.position === 'static') continue;
|
||||||
}
|
|
||||||
if (overflowRegex.test(style.overflow + style.overflowY + style.overflowX)) return parent;
|
if (overflowRegex.test(style.overflow + style.overflowY + style.overflowX)) return parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user