Created
October 21, 2013 08:09
-
-
Save jswhisperer/7080254 to your computer and use it in GitHub Desktop.
getBoundingClientRect() js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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