Skip to content

Instantly share code, notes, and snippets.

@lmartins
Created April 11, 2014 11:58
Show Gist options
  • Save lmartins/10462251 to your computer and use it in GitHub Desktop.
Save lmartins/10462251 to your computer and use it in GitHub Desktop.
Get Click Position
getClickPosition = (e) ->
parentPosition = getPosition e.currentTarget
xPos = e.clientX - parentPosition.x
yPos = e.clientY - parentPosition.y
# console.log "X:#{xPos} Y:#{yPos}"
getPosition = (element) ->
xPos = 0
yPos = 0
while (element)
xPos += element.offsetLeft - element.scrollLeft + element.clientLeft
yPos += element.offsetTop - element.scrollTop + element.clientTop
element = element.offsetParent
x: xPos
y: yPos
clickTarget = document.querySelector '.clickTarget'
clickTarget.addEventListener 'click', getClickPosition
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment