Skip to content

Instantly share code, notes, and snippets.

@techkuz
Created June 5, 2018 10:03
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 techkuz/7872539e5d3467fc1d3e07ca9e32c48b to your computer and use it in GitHub Desktop.
Save techkuz/7872539e5d3467fc1d3e07ca9e32c48b to your computer and use it in GitHub Desktop.
left and top positions of element - javascript
function getOffset(el) {
el = el.getBoundingClientRect();
return {
left: el.left + window.scrollX,
top: el.top + window.scrollY
}
}
// https://stackoverflow.com/a/28222246/7127824
// getOffset(element).left
// getOffset(element).top
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment