I thought $(window).scrollTop
would tell me by how much I had scrolled, but...
If I scroll a bit, I'll get:
$(window).scrollTop(): 0
$('#react-root')[0].scrollTop: 0
$('#react-root')[0].getBoundingClientRect().top: -450 // that seems to be correct
#react-root
being directly attached to the body, and containing everything. Is it how things are supposed to happen?
==== Edit ===
Ok I happened to have an unusual overflow settings:
html {
overflow: hidden;
height: 100%;
}
body {
height: 100%;
overflow: scroll;
}
That I did to avoid over scrolling (https://stackoverflow.com/a/17899813/2054629) and forgot about it.
Here is a jsfiddle that reproduces the issue https://jsfiddle.net/7ugf4jm5/7/ where none of the elements has a positive scrolltop, while scrolling do happen
==== Goal ====
In the setting described by the jsfiddle, I'm interested to get the scroll offset (it seems that getBoundingClientRect
returns it) and be able to reset the scroll position to the top.