Get scroll position of HTMLElement / window

This commit is contained in:
Renato de Leão
2017-12-12 11:52:09 +00:00
parent 82fa5f5eac
commit f275982100
2 changed files with 29 additions and 0 deletions

View File

@ -0,0 +1,14 @@
## Get Scroll Position
Get the current distance scrolled by `window` or `HTMLElement` as an {x,y} object
```js
const getScrollPos = (scroller = window) => {
let x = (scroller.pageXOffset !== undefined) ? scroller.pageXOffset : scroller.scrollLeft;
let y = (scroller.pageYOffset !== undefined) ? scroller.pageYOffset : scroller.scrollTop;
return {x, y}
}
// getScrollPos() -> {x: number, y: number}
```