Chrome 61 body doesn't scroll
JavascriptGoogle ChromeScrollJavascript Problem Overview
Does anyone know why assigning scrollTop
on the body element no longer works?
eg:
document.body.scrollTop = 200
causes the document not to scroll.
Cause: Chrome finally made scrolling spec conformant in version 61
Solution: Use scrollingElement
Update the example to:
var scrollNode = document.scrollingElement ?
document.scrollingElement : document.body;
scrollNode.scrollTop = 200;
Javascript Solutions
Solution 1 - Javascript
The solution described at the end of this question (checking for document.scrollingElement
or falling back to document.body
) won't work on IE, as it doesn't support document.scrollingElement
(docs), and in IE, the scroll element is the HTML element.
I'd therefore suggest that a better solution for this would be something like;
var scrollNode = document.scrollingElement || document.documentElement;
Which should work for all modern browsers.
As a sidenote, it's interesting to consider that the scrollingElement
property seems to have been added for the sole purpose of making it so that we don't need checks/fallbacks for getting the root scrolling element, but due to more browser incompatibilities, we still need a check/fallback in order to use scrollingElement
.
Isn't web dev fun?
Solution 2 - Javascript
Ended adding this code to the document ready and it works. also, i had problems with some tooltips that were misplaced and this code fixed it:
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 could help you.