Created
April 11, 2014 11:58
-
-
Save lmartins/10462251 to your computer and use it in GitHub Desktop.
Get Click Position
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
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