Skip to content

Instantly share code, notes, and snippets.

@jswhisperer
Created October 21, 2013 08:09
Show Gist options
  • Select an option

  • Save jswhisperer/7080254 to your computer and use it in GitHub Desktop.

Select an option

Save jswhisperer/7080254 to your computer and use it in GitHub Desktop.
getBoundingClientRect() js
var box = document.getElementById('box'),
x, y, w;
x = box.getBoundingClientRect().left;
y = box.getBoundingClientRect().top;
w = box.getBoundingClientRect().width; //|| box.offsetWidth;
h = box.getBoundingClientRect().height; // || box.offsetHeight;
console.log(x, y, w, h);
// top: How many pixels the top edge of the element is from the topmost edge of the viewport
// left: How many pixels the left edge of the element is from the leftmost edge of the viewport
// right: How many pixels the right edge of the element is from the leftmost edge of the viewport
// bottom: How many pixels the bottom edge of the element is from the topmost edge of the viewport
// width: The width of the element
// height: The height of the element
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment