To get the vertical position of the scroll bar for the current page, use:
Document.documentElement.scrollTop;
Instead of:
Document.body.scrollTop;
The documentelement corresponds to an HTML tag, and the body corresponds to the body tag.
DocumentElement are not commonly used. This is easy to make mistakes in development, many online examples, using DOCUMENT.BODY.SCROLLTOP, in fact, the correct value is not.
(What is the ScrollTop property?)
In some cases, the height of the content in the element exceeds the height of the element itself, scrolltop refers to the height of the portion of the element that exceeds the upper boundary of the element, that is, the height of the content in the scrolltop element, or that is understood as the content in the element moves up the process, The unseen part of the run can also be understood as the offset of the scrollbar relative to its top. )
Get the scroll position of the current page in JavaScript