Document: scrollingElement property
The scrollingElement read-only property of the
Document interface returns a reference to the Element that
scrolls the document. In standards mode, this is the root element of the
document, document.documentElement.
When in quirks mode, the scrollingElement attribute returns the HTML
body element if it exists and is not potentially scrollable, otherwise it returns null. This may look surprising but is true according to both the specification and browsers.
Value
The Element that scrolls the document, usually the root element (unless not in standard mode).
Examples
const scrollElm = document.scrollingElement;
scrollElm.scrollTop = 0;
Specifications
Browser compatibility
这篇文档对你有帮助吗?
谢谢你的反馈!