Created
October 22, 2014 20:54
-
-
Save gregkepler/13f7ac4c34ab7ca91bea to your computer and use it in GitHub Desktop.
returns the bounds of a dom element wrapped in an angular element
This file contains 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
// 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