How can I get the scrollbar position with JavaScript?

I’m trying to detect the position of the browser’s scrollbar with JavaScript to decide where in the page the current view is.

My guess is that I have to detect where the thumb on the track is, and then the height of the thumb as a percentage of the total height of the track. Am I over-complicating it, or does JavaScript offer an easier solution than that? What would some code look like?

10 Answers
10

Leave a Comment