Created
May 4, 2011 04:42
-
-
Save anonymous/954770 to your computer and use it in GitHub Desktop.
coffeescript global offset
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
findPos = (obj) -> | |
[left, top] = [obj.offsetLeft, obj.offsetTop] | |
offsets = while obj = obj.offsetParent | |
[obj.offsetLeft, obj.offsetTop] | |
for l, t of offsets | |
left += l | |
top += t | |
left: left, top: top | |
# This version is not quite legal, but along the lines of my thinking.. | |
findPos = (obj) -> | |
[left, top] = [obj.offsetLeft, obj.offsetTop] | |
for t, l of (while obj = obj.offsetParent [obj.offsetLeft, obj.offsetTop]) | |
left += l | |
top += t | |
left: left, top: top |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment