Skip to content

Instantly share code, notes, and snippets.

@michiel
Created May 7, 2013 17:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michiel/5534559 to your computer and use it in GitHub Desktop.
Save michiel/5534559 to your computer and use it in GitHub Desktop.
# Find element's top-left position, cross-browser
# via http://www.kirupa.com/html5/get_element_position_using_javascript.htm
topLeft = (e)->
x = y = 0
while e
x += e.offsetLeft - e.scrollLeft + e.clientLeft
y += e.offsetTop - e.scrollTop + e.clientTop
e = e.offsetParent
x : x
y : y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment