getElementDocumentPosition function

Pair<num> getElementDocumentPosition(
  1. Element element
)

Returns the X and Y position of Element int the Document.

Implementation

Pair<num> getElementDocumentPosition(Element element) {
  var obj = getVisibleNode(element);

  num top = obj!.offsetTop;
  num left = obj.offsetLeft;

  if (obj.offsetParent != null) {
    do {
      top += obj!.offsetTop;
      left += obj.offsetLeft;
    } while ((obj = obj.offsetParent) != null);
  }

  return Pair<num>(left, top);
}