MCPcopy Create free account
hub / github.com/andreadev-it/stacking-contexts-inspector / getRelativePosition

Function getRelativePosition

src/scripts/content.js:68–85  ·  view source on GitHub ↗

* Get the relative position of a specific element in the page (iframes included) * * @param {StackingContext} context * @return {Object} The relative position of the context frame

(context)

Source from the content-addressed store, hash-verified

66 * @return {Object} The relative position of the context frame
67 */
68function getRelativePosition(context) {
69 let relativePosition = { top: 0, left: 0 };
70 let current = context;
71
72 while (current) {
73 if (current.frame == null) break;
74
75 if (current.type === "container") {
76 let frameBCR = current.frame.getBoundingClientRect();
77 relativePosition.top += frameBCR.top;
78 relativePosition.left += frameBCR.left;
79 }
80
81 current = current.parent;
82 }
83
84 return relativePosition;
85}
86
87/**
88 * Remove the highlight element from the page.

Callers 1

highlightContextFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected