I came across an unusual bug that started popping up when I set the body as a relatively positioned element with a 39px margin (to accommodate a toolbar at the top of a page).
Typically, when you refer to guides on calculating the position of a page element, you'll encounter code like this:
function getPos(elt) {
var pt = [0, 0];
while (elt.offsetParent !== null) {
pt[0] += elt.offsetLeft;
pt[1] += elt.offsetTop;
elt = elt.offsetParent;
}
return pt;
}
This method works well, even if the <body> tag has a margin. However, if the body is also position:relative, the returned value becomes too small because it doesn't take into account the body element's margins.
How can I 1) identify if the body is relatively positioned and 2) determine the exact margins so I can include them in the calculations?
It's crucial for me to have page coordinates so I can compare them with MouseEvent PageX and PageY values.