Permalink
Browse files

safe to use getBoundingClientRect() for offset()

  • Loading branch information...
1 parent c8d1981 commit 6014d7389f3c48d8c069ab985acd95b96572c005 @rvagg rvagg committed Oct 27, 2012
Showing with 11 additions and 23 deletions.
  1. +5 −11 bonzo.js
  2. +1 −1 bonzo.min.js
  3. +5 −11 src/bonzo.js
View
@@ -793,19 +793,13 @@
, width: 0
}
var el = this[0]
+ , de = el.ownerDocument.documentElement
+ , bcr = el.getBoundingClientRect()
+ , scroll = getWindowScroll()
, width = el.offsetWidth
, height = el.offsetHeight
- , top = el.offsetTop
- , left = el.offsetLeft
- while (el = el.offsetParent) {
- top = top + el.offsetTop
- left = left + el.offsetLeft
-
- if (el != doc.body) {
- top -= el.scrollTop
- left -= el.scrollLeft
- }
- }
+ , top = bcr.top + scroll.y - Math.max(0, de && de.clientTop, doc.body.clientTop)
+ , left = bcr.left + scroll.x - Math.max(0, de && de.clientLeft, doc.body.clientLeft)
return {
top: top
Oops, something went wrong.

0 comments on commit 6014d73

Please sign in to comment.