Created
November 15, 2020 13:26
-
-
Save AitorAlejandro/492a2eb6179d5cd13a1c9ccc9053c1ef to your computer and use it in GitHub Desktop.
Get the scroll position of the current page
This file contains hidden or 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
| 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