636 B
636 B
title, tags, cover, firstSeen, lastUpdated
| title | tags | cover | firstSeen | lastUpdated |
|---|---|---|---|---|
| Scroll position | browser | tranquil-lake | 2017-12-17T17:55:51+02:00 | 2020-10-19T22:49:51+03:00 |
Returns the scroll position of the current page.
- Use
Window.pageXOffsetandWindow.pageYOffsetif they are defined, otherwiseElement.scrollLeftandElement.scrollTop. - Omit the single argument,
el, to use the globalWindowobject.
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}