Skip to content

Instantly share code, notes, and snippets.

Created May 4, 2011 04:42
Show Gist options
  • Save anonymous/954770 to your computer and use it in GitHub Desktop.
Save anonymous/954770 to your computer and use it in GitHub Desktop.
coffeescript global offset
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