Search code examples
javascriptviewportline-numbers

Get text at top of screen during scroll?


I'm looking for a way for javascript to tell how far a user has scrolled down the screen.

Instead of doing this through x, y coordinates is there a way to pull what's at the top of the viewport?

Either the text / line number or the current top element in the viewport?


Solution

  • No, you can't. You have to set scroll events and update x and y values. Then, with those values, you can get the element at this position. https://developer.mozilla.org/en/DOM/document.elementFromPoint http://msdn.microsoft.com/en-us/library/ms536417%28VS.85%29.aspx