Window.pageXOffset
and Window.pageYOffset
if they are defined, otherwise Element.scrollLeft
and Element.scrollTop
.el
, to use a default value of window
.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}
Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️