jQuery scrollTop() returns 0 for all elements jQuery scrollTop() returns 0 for all elements angularjs angularjs

jQuery scrollTop() returns 0 for all elements


As @Hans commented, there wasn't actually a problem.I had a wrapping element, that was positioned absolute with:

top:0;bottom:0;left:0;right:0;overflow:auto

So The window's scrollTop was always 0, and the scrollbar actually belonged to the wrapping element.

Since I could't get rid of the wrapping element's positioning, I used ui-router's $stateChangeSuccess event, and manually scrolled the wrapping element to the top.


From the console, try

console.log(frames)console.log(frames.top.scrollY)

If window.scrollY is showing 0, then the reference frame must not be the window. Do you have any iframes on the page? console.log of frames will show the list of frames on the page.
Hope that helps.


My code is happend this problem too, and I found a body{overflow: hidden;} is the reason, I remove "overflow: hidden;" and all is well.