To get the current scroll state value, you can use the pageXOffset
and pageYOffset
properties in the global window
object in JavaScript.
// Current Scroll state value from top
const scrollValuefromTop = window.pageYOffset;
// Current Scroll state value from left
const scrollValuefromLeft = window.pageXOffset;
- The
pageYOffset
will give the scroll value state which is from the top of the page. - And the
pageXOffset
will the scroll value state which is from the left of the page.
See this example live in JSBin.
Top comments (0)