ded / bonzo

library agnostic, extensible DOM utility
Other
1.32k stars 137 forks source link

offset() doesn't account for parents' scrollTop & scrollLeft #76

Closed runningskull closed 12 years ago

runningskull commented 12 years ago

In the current version, an element's offset() doesn't take into account its parents' scrollLeft and scrollTop. Those should take that into account, for all elements except the body.

This patch teaches offset() to take scrolling into account. I included a couple tests, but they don't test every possible edge case (negative scroll values, for instance) b/c it didn't seem necessary.

Let me know if it needs more coverage, or if there's some reason we shouldn't be doing this at all.

ps. This is also how jQuery's offset() works, although they use getBoundingClientRect() if possible. I haven't looked into the pros/cons of that approach.

ded commented 12 years ago

cool. thanks for this!