Skip to content

Instantly share code, notes, and snippets.

@rayros
Created January 2, 2016 12:50
Show Gist options
  • Select an option

  • Save rayros/c96c04f0b74a693afff0 to your computer and use it in GitHub Desktop.

Select an option

Save rayros/c96c04f0b74a693afff0 to your computer and use it in GitHub Desktop.
function getPosition(element) {
var xPosition = 0, yPosition = 0;
while(element) {
xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
element = element.offsetParent;
}
return { x: xPosition, y: yPosition };
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment