Skip to content

Instantly share code, notes, and snippets.

@aviogreen
Created October 30, 2015 03:39
Show Gist options
  • Save aviogreen/d470fefdda71b06f6841 to your computer and use it in GitHub Desktop.
Save aviogreen/d470fefdda71b06f6841 to your computer and use it in GitHub Desktop.
var bodyRect = document.body.getBoundingClientRect(),
elemRect = document.getElementById('keroro').getBoundingClientRect(),
offset = elemRect.top - bodyRect.top;
alert('Element is ' + offset + ' vertical pixels from <body>');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment