Skip to content

Instantly share code, notes, and snippets.

@AitorAlejandro
Created November 15, 2020 13:26
Show Gist options
  • Save AitorAlejandro/492a2eb6179d5cd13a1c9ccc9053c1ef to your computer and use it in GitHub Desktop.
Save AitorAlejandro/492a2eb6179d5cd13a1c9ccc9053c1ef to your computer and use it in GitHub Desktop.
Get the scroll position of the current page
const getScrollPosition = (el = window) => ({
x: el.pageXOffset !== undefined ? el.pageXOffset : el.scrollLeft,
y: el.pageYOffset !== undefined ? el.pageYOffset : el.scrollTop
});
// Example
getScrollPosition(); // {x: 0, y: 200}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment