Skip to content

Function: getOffsetPosition() ​

ts
function getOffsetPosition(ele): {
  left: number;
  top: number;
};

Gets the offset (left, top) position of the specified element relative to its parent element.

Parameters ​

ParameterTypeDescription
eleHTMLElementThe element to get the offset position for.

Returns ​

ts
{
  left: number;
  top: number;
}

The offset (left, top) position of the element relative to its parent.

left ​

ts
left: number;

top ​

ts
top: number;

Example ​

ts
const el = document.createElement('div')
document.body.appendChild(el)
const offset = getOffsetPosition(el)
console.log(offset.left, offset.top)

Since ​

1.0.0

Released under the MIT License.