ES6 snippet - JavaScript - scroll snippet - window

PHOTO EMBED

Wed Nov 04 2020 08:13:29 GMT+0000 (UTC)

Saved by @julien #javascript

const getScrollPosition = (el = window) => ({
  x: el.pageXOffset !== undefined ? el.pageXOffset : el.scrollLeft,
  y: el.pageYOffset !== undefined ? el.pageYOffset : el.scrollTop
});

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

https://medium.com/swlh/24-modern-es6-code-snippets-to-solve-practical-js-problems-3609f301859e