Chrome 61 body doesn't scroll

Does anyone know why assigning scrollTop in body element no longer works?

for example: document.body.scrollTop = 200

causes the document to not scroll.

Reason : Chrome finally scrolls spec-compatible in version 61

Solution : use scrollingElement

Update example to:

 var scrollNode = document.scrollingElement ? document.scrollingElement : document.body; scrollNode.scrollTop = 200; 
+54
javascript google-chrome scroll
Jul 12 '17 at 15:27
source share
2 answers

The solution described at the end of this question (checking for document.scrollingElement or returning to document.body ) will not work on IE because it does not support document.scrollingElement ( docs ), and in IE the scroll element is an HTML element.

I would suggest that the best solution for this would be something like:

 var scrollNode = document.scrollingElement || document.documentElement; 

What should work for all modern browsers.




As a side element, it’s interesting to take into account that the scrollingElement property seems to have been added for the sole purpose of making it such that we don’t need checks / backups to get the root scroll element, but because of more browser incompatibility, we still need to check / backup to use scrollingElement .

Don't you like a web developer?

+15
Sep 12 '17 at 16:19 on
source share

Finishing adding this code to the document is done and everything works. Also, I had problems with some tooltips, and this code fixed this:

  window.onload = function () { var GetDocumentScrollTop = function () { var isScrollBodyIE = ASPx.Browser.IE && ASPx.GetCurrentStyle(document.body).overflow == "hidden" && document.body.scrollTop > 0; if (ASPx.Browser.WebKitFamily || isScrollBodyIE) { if (ASPx.Browser.MacOSMobilePlatform) return window.pageYOffset; else if (ASPx.Browser.WebKitFamily) return document.documentElement.scrollTop || document.body.scrollTop; return document.body.scrollTop; } else return document.documentElement.scrollTop; }; var _aspxGetDocumentScrollTop = function () { if (__aspxWebKitFamily) { if (__aspxMacOSMobilePlatform) return window.pageYOffset; else return document.documentElement.scrollTop || document.body.scrollTop; } else return document.documentElement.scrollTop; } if (window._aspxGetDocumentScrollTop) { window._aspxGetDocumentScrollTop = _aspxGetDocumentScrollTop; window.ASPxClientUtils.GetDocumentScrollTop = _aspxGetDocumentScrollTop; } else { window.ASPx.GetDocumentScrollTop = GetDocumentScrollTop; window.ASPxClientUtils.GetDocumentScrollTop = GetDocumentScrollTop; } }; 

Hope this helps you.

-one
Oct 06 '17 at 20:31 on
source share



All Articles