Chrome 61机身不滚动

有谁知道为什么分配身体元素的scrollTop不再有效?

例如: document.body.scrollTop = 200

导致文档不滚动。

原因 :Chrome在版本61中最终做出了符合滚动规范的规范

解决scheme :使用scrollingElement

将示例更新为:

 var scrollNode = document.scrollingElement ? document.scrollingElement : document.body; scrollNode.scrollTop = 200; 

在这个问题的最后描述的解决scheme(检查document.scrollingElement或回落到document.body )将无法在IE浏览器上工作,因为它不支持document.scrollingElement ( docs ),在IE中,scroll元素是HTML元素。

因此,我build议对此的更好的解决scheme是类似的;

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

哪些应该适用于所有现代浏览器。


作为一个旁注,有趣的是考虑到scrollingElement属性似乎是为了使得我们不需要检查/回退来获得根滚动元素的唯一目的而添加的,但是由于更多的浏览器不兼容性,我们仍然需要一个检查/回退为了使用scrollingElement

不是networking开发乐趣?

你好,我有一个类似的问题,我结束了这个代码添加到文档准备就绪,它的工作原理。 另外,我有一些错误的工具提示的问题,这个代码修复它。

  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; } }; 

希望这可以帮助你。

谢谢