Google chrome document.body.scrollTop always returns 0

On Google, chrome document.body.scrollTop always returns 0.

I'm trying to

if (window.pageYOffset > 0) { st = window.pageYOffset; } else if (document.documentElement.scrollTop > 0) { st = document.documentElement.scrollTop; } else { st = document.body.scrollTop; } 

But does not work. document.body.scrollTop works in firefox.

Even in the chrome console, when I have this code in the console, it does not work.

 enter code here $('html, body').stop().animate({ scrollTop: 50 }, 500); 
+5
source share
1 answer

I hit too. According to this issue, this behavior has changed between Chrome 60 and Chrome 61:

https://bugs.chromium.org/p/chromium/issues/detail?id=766938

From what I read, the new behavior is actually more standardized. Proposed fix from comment # 5 for this issue:

If you are looking for an interoperable way to request scrollTop, you can use the window.scrollY attribute or do something like document.documentElement.scrollTop || document.body.scrollTop

+5
source

Source: https://habr.com/ru/post/1267349/


All Articles