mirror of
				https://github.com/Tencent/tmagic-editor.git
				synced 2025-11-04 10:49:51 +08:00 
			
		
		
		
	chore(stage): 修改判断position的方法
This commit is contained in:
		
							parent
							
								
									c2de910f3c
								
							
						
					
					
						commit
						7467aba75e
					
				@ -73,31 +73,19 @@ export const isSameDomain = (targetUrl = '', source = globalThis.location.host)
 | 
				
			|||||||
  return getHost(targetUrl) === source;
 | 
					  return getHost(targetUrl) === source;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const isAbsolute = (el?: HTMLElement): boolean => {
 | 
					export const isAbsolute = (style: CSSStyleDeclaration): boolean => style.position === 'absolute';
 | 
				
			||||||
  if (!el) return false;
 | 
					 | 
				
			||||||
  return getComputedStyle(el).position === 'absolute';
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const isRelative = (el?: HTMLElement): boolean => {
 | 
					export const isRelative = (style: CSSStyleDeclaration): boolean => style.position === 'relative';
 | 
				
			||||||
  if (!el) return false;
 | 
					 | 
				
			||||||
  return getComputedStyle(el).position === 'relative';
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const isStatic = (el?: HTMLElement): boolean => {
 | 
					export const isStatic = (style: CSSStyleDeclaration): boolean => style.position === 'static';
 | 
				
			||||||
  if (!el) return false;
 | 
					 | 
				
			||||||
  return getComputedStyle(el).position === 'static';
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const isFixed = (el?: HTMLElement): boolean => {
 | 
					export const isFixed = (style: CSSStyleDeclaration): boolean => style.position === 'fixed';
 | 
				
			||||||
  if (!el) return false;
 | 
					 | 
				
			||||||
  return getComputedStyle(el).position === 'fixed';
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const isFixedParent = (el: HTMLElement) => {
 | 
					export const isFixedParent = (el: HTMLElement) => {
 | 
				
			||||||
  let fixed = false;
 | 
					  let fixed = false;
 | 
				
			||||||
  let dom = el;
 | 
					  let dom = el;
 | 
				
			||||||
  while (dom) {
 | 
					  while (dom) {
 | 
				
			||||||
    fixed = isFixed(dom);
 | 
					    fixed = isFixed(getComputedStyle(dom));
 | 
				
			||||||
    if (fixed) {
 | 
					    if (fixed) {
 | 
				
			||||||
      break;
 | 
					      break;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -112,22 +100,22 @@ export const isFixedParent = (el: HTMLElement) => {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
export const getMode = (el: HTMLElement): Mode => {
 | 
					export const getMode = (el: HTMLElement): Mode => {
 | 
				
			||||||
  if (isFixedParent(el)) return Mode.FIXED;
 | 
					  if (isFixedParent(el)) return Mode.FIXED;
 | 
				
			||||||
  if (isStatic(el) || isRelative(el)) return Mode.SORTABLE;
 | 
					  const style = getComputedStyle(el);
 | 
				
			||||||
 | 
					  if (isStatic(style) || isRelative(style)) return Mode.SORTABLE;
 | 
				
			||||||
  return Mode.ABSOLUTE;
 | 
					  return Mode.ABSOLUTE;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
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 (style.position === 'fixed') return null;
 | 
					  if (isFixed(style)) 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 (excludeStaticParent && style.position === 'static') continue;
 | 
					    if (isAbsolute(style) && isStatic(style)) 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