Skip to content

Instantly share code, notes, and snippets.

@gregkepler
Created October 22, 2014 20:54
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 gregkepler/13f7ac4c34ab7ca91bea to your computer and use it in GitHub Desktop.
Save gregkepler/13f7ac4c34ab7ca91bea to your computer and use it in GitHub Desktop.
returns the bounds of a dom element wrapped in an angular element
// originall from from http://cvmlrobotics.blogspot.com/2013/03/angularjs-get-element-offset-position.html
function bounds( elm ) {
try {return elm.offset();} catch(e) {}
var rawDom = elm[0];
var _x = 0;
var _y = 0;
var body = document.documentElement || document.body;
var scrollX = window.pageXOffset || body.scrollLeft;
var scrollY = window.pageYOffset || body.scrollTop;
_x = rawDom.getBoundingClientRect().left + scrollX;
_y = rawDom.getBoundingClientRect().top + scrollY;
var _width = rawDom.getBoundingClientRect().width;
var _height = rawDom.getBoundingClientRect().height;
return { left: _x, top:_y, width:_width, height:_height };
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment