MCPcopy Create free account
hub / github.com/bvaughn/react-virtualized / getPositionOffset

Function getPositionOffset

lib/utils/scrollElement/dimensions.ts:46–67  ·  view source on GitHub ↗
(
  element: Element,
  container: ResolvedScrollElement
)

Source from the content-addressed store, hash-verified

44 * In this case the body’s top or left position will be a negative number and this element’s top or left will be increased (by that amount).
45 */
46export function getPositionOffset(
47 element: Element,
48 container: ResolvedScrollElement
49): Offset {
50 if (isWindow(container) && document.documentElement) {
51 const containerElement = document.documentElement;
52 const elementRect = getBoundingBox(element);
53 const containerRect = getBoundingBox(containerElement);
54 return {
55 top: elementRect.top - containerRect.top,
56 left: elementRect.left - containerRect.left
57 };
58 } else {
59 const scrollOffset = getScrollOffset(container);
60 const elementRect = getBoundingBox(element);
61 const containerRect = getBoundingBox(container as Element);
62 return {
63 top: elementRect.top + scrollOffset.top - containerRect.top,
64 left: elementRect.left + scrollOffset.left - containerRect.left
65 };
66 }
67}
68
69/**
70 * Gets the vertical and horizontal scroll amount of the element, accounting for IE compatibility

Callers 3

dimensions.test.tsFile · 0.90
measureViewportFunction · 0.90
scrollToFunction · 0.90

Calls 3

isWindowFunction · 0.85
getBoundingBoxFunction · 0.85
getScrollOffsetFunction · 0.85

Tested by

no test coverage detected