In Google chrome document.body.scrollTop always returns 0.
I try
if (window.pageYOffset > 0) {
st = window.pageYOffset;
} else if (document.documentElement.scrollTop > 0) {
st = document.documentElement.scrollTop;
} else {
st = document.body.scrollTop;
}
But not working. document.body.scrollTop is working in firefox.
Even in chrome console when i this code in console it is not working.
enter code here
$('html, body').stop().animate({
scrollTop: 50
}, 500);
The Element. scrollTop property gets or sets the number of pixels that an element's content is scrolled vertically. An element's scrollTop value is a measurement of the distance from the element's top to its topmost visible content.
Scrolling: scrollTo, scrollBy, scrollIntoView Regular elements can be scrolled by changing scrollTop/scrollLeft . We can do the same for the page using document. documentElement.
I hit this as well. According to this issue this behavior changed between Chrome 60 and Chrome 61:
https://bugs.chromium.org/p/chromium/issues/detail?id=766938
From what I have read the new behavior is actually more standards compliant. The suggested fix from comment #5 for that issue is:
If you are looking for an interoperable way of querying scrollTop you can use the window.scrollY attribute or doing something like document.documentElement.scrollTop || document.body.scrollTop
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With