Quellcode durchsuchen

make sure getBoundingClientRect is defined

Gildas vor 5 Jahren
Ursprung
Commit
b08ab7c377

+ 3 - 2
lib/single-file/processors/hooks/content/content-hooks-frames-web.js

@@ -166,14 +166,15 @@
 			dispatchResizeEvent();
 			const docBoundingRect = scrollingElement.getBoundingClientRect();
 			[...observers].forEach(([intersectionObserver, observer]) => {
-				const rootBoundingRect = observer.options && observer.options.root && observer.options.root.getBoundingClientRect();
+				const getBoundingClientRectDefined = observer.options && observer.options.root && observer.options.root.getBoundingClientRect;
+				const rootBoundingRect = getBoundingClientRectDefined && observer.options.root.getBoundingClientRect();
 				const targetElements = observedElements.get(intersectionObserver);
 				if (targetElements) {
 					observer.callback(targetElements.map(target => {
 						const boundingClientRect = target.getBoundingClientRect();
 						const isIntersecting = true;
 						const intersectionRatio = 1;
-						const rootBounds = observer.options && observer.options.root ? rootBoundingRect : docBoundingRect;
+						const rootBounds = getBoundingClientRectDefined ? rootBoundingRect : docBoundingRect;
 						const time = 0;
 						return { target, intersectionRatio, boundingClientRect, intersectionRect: boundingClientRect, isIntersecting, rootBounds, time };
 					}), intersectionObserver);