Menu

gitpiper

getScrollPosition javascript Code Snippet in 2024

browserintermediate

Last Updated: 20 April 2024

Returns the scroll position of the current page.

  • Use Window.pageXOffset and Window.pageYOffset if they are defined, otherwise Element.scrollLeft and Element.scrollTop.
  • Omit the single argument, 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}

javascript snippet similar to getScrollPosition For You in April 2024

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2024 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️