Kaynağa Gözat

fix(@vben-core/shared): element outside viewport, the element visible rect each prop expect 0 (#7120)

* fix(@vben-core/shared): element outside viewport

* fix(@vben-core/shared): element outside viewport
橙子 4 ay önce
ebeveyn
işleme
203ee9b623
1 değiştirilmiş dosya ile 12 ekleme ve 0 silme
  1. 12 0
      packages/@core/base/shared/src/utils/dom.ts

+ 12 - 0
packages/@core/base/shared/src/utils/dom.ts

@@ -41,6 +41,18 @@ export function getElementVisibleRect(
   const left = Math.max(rect.left, 0);
   const right = Math.min(rect.right, viewWidth);
 
+  // 如果元素完全不可见,则返回一个空的矩形
+  if (top >= viewHeight || bottom <= 0 || left >= viewWidth || right <= 0) {
+    return {
+      bottom: 0,
+      height: 0,
+      left: 0,
+      right: 0,
+      top: 0,
+      width: 0,
+    };
+  }
+
   return {
     bottom,
     height: Math.max(0, bottom - top),