Skip to content

Home

Scroll position

Returns 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
});

getScrollPosition(); // {x: 0, y: 200}

More like this

Start typing a keyphrase to see matching snippets.