Skip to content

getOffset

Mike Byrne edited this page Jan 25, 2022 · 2 revisions

description

Get the current coordinates of a node, relative to the document, corrected by scroll. Uses getBoundingClientRect

requires

  • nothing

parameters

  • node - required

returns

  • object:
{
  top: 100,
  left: 200,
  bottom: 300,
  right: 400,
  width: 500,
  height: 600
}

example usage:

var node = document.getElementById('foo');
var offset = getOffset(node); // object
var offsetTop = getOffset(node).top; // number
Clone this wiki locally