Files
30-seconds-of-code/snippets/getScrollPosition.md
Stefan Feješ 82b850fd00 Fix test cases
2017-12-17 22:26:07 +01:00

14 lines
464 B
Markdown

### getScrollPosition
Returns the scroll position of the current page.
Use `pageXOffset` and `pageYOffset` if they are defined, otherwise `scrollLeft` and `scrollTop`.
You can omit `el` to use a default value of `window`.
```js
const getScrollPosition = (el = window) =>
({x: (el.pageXOffset !== undefined) ? el.pageXOffset : el.scrollLeft,
y: (el.pageYOffset !== undefined) ? el.pageYOffset : el.scrollTop});
// getScrollPosition() -> {x: 0, y: 200}
```