Published February 2, 2021
To get the current scroll state value, you can use the
pageYOffset properties in the global
// Current Scroll state value from top const scrollValuefromTop = window.pageYOffset; // Current Scroll state value from left const scrollValuefromLeft = window.pageXOffset;
pageYOffsetwill give the scroll value state which is from the top of the page.
- And the
pageXOffsetwill the scroll value state which is from the left of the page.
See this example live in JSBin.