DEV Community

Cover image for How to get the current scroll state value of the window using JavaScript?
MELVIN GEORGE
MELVIN GEORGE

Posted on • Originally published at melvingeorge.me

4

How to get the current scroll state value of the window using JavaScript?

Originally posted here!

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;
Enter fullscreen mode Exit fullscreen mode
  • 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.

Feel free to share if you found this useful 😃.


SurveyJS custom survey software

JavaScript UI Libraries for Surveys and Forms

SurveyJS lets you build a JSON-based form management system that integrates with any backend, giving you full control over your data and no user limits. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more.

Learn more

Top comments (0)

Neon image

Next.js applications: Set up a Neon project in seconds

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Get started →

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, cherished by the supportive DEV Community. Coders of every background are encouraged to bring their perspectives and bolster our collective wisdom.

A sincere “thank you” often brightens someone’s day—share yours in the comments below!

On DEV, the act of sharing knowledge eases our journey and forges stronger community ties. Found value in this? A quick thank-you to the author can make a world of difference.

Okay