Skip to content

Instantly share code, notes, and snippets.

@jfsiii
Created September 26, 2013 22:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jfsiii/6721340 to your computer and use it in GitHub Desktop.
Save jfsiii/6721340 to your computer and use it in GitHub Desktop.
*sort of* like getBoundingClientRect() but it takes transforms into account.
function getRenderedRectangle(element, root) {
if (!root) root = document;
var width = element.offsetWidth,
height = element.offsetHeight,
topLeft = webkitConvertPointFromPageToNode(root, webkitConvertPointFromNodeToPage(element, new WebKitPoint(0, 0))),
topRight = webkitConvertPointFromPageToNode(root, webkitConvertPointFromNodeToPage(element, new WebKitPoint(width, 0))),
bottomLeft = webkitConvertPointFromPageToNode(root, webkitConvertPointFromNodeToPage(element, new WebKitPoint(0, height))),
bottomRight = webkitConvertPointFromPageToNode(root, webkitConvertPointFromNodeToPage(element, new WebKitPoint(width, height)));
return [topLeft, topRight, bottomRight, bottomLeft];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment