Kaynağa Gözat

coordcache can operate when element not in dom

Adam Shaw 8 yıl önce
ebeveyn
işleme
3718e880fc
1 değiştirilmiş dosya ile 15 ekleme ve 8 silme
  1. 15 8
      src/common/CoordCache.ts

+ 15 - 8
src/common/CoordCache.ts

@@ -49,16 +49,23 @@ export default class CoordCache {
       offsetParentEl = this.els[0].offsetParent as HTMLElement
     }
 
-    let offsetParentRect = offsetParentEl.getBoundingClientRect()
-    this.origin = { top: offsetParentRect.top, left: offsetParentRect.left }
+    if (offsetParentEl) {
+      let offsetParentRect = offsetParentEl.getBoundingClientRect()
+      this.origin = { top: offsetParentRect.top, left: offsetParentRect.left }
 
-    this.boundingRect = this.queryBoundingRect()
+      this.boundingRect = this.queryBoundingRect()
 
-    if (this.isHorizontal) {
-      this.buildElHorizontals()
-    }
-    if (this.isVertical) {
-      this.buildElVerticals()
+      if (this.isHorizontal) {
+        this.buildElHorizontals()
+      }
+      if (this.isVertical) {
+        this.buildElVerticals()
+      }
+    } else {
+      this.lefts = []
+      this.rights = []
+      this.tops = []
+      this.bottoms = []
     }
   }