javascript scrollTop Gets the offset of the scroll bar relative to its top (such as making a "return to top" button that automatically displays and hides). In practical applications, we often encounter the following problems:
document.documentElement.scrollTop is always 0 in Chrome
document.body.scrollTop is always 0 in IE and Firefox
1, each Differences between window.pageYOffset/document.documentElement.scrollTop/document.body.scrollTop under the browser
Example:
No doctype:
window.pageYOffset: undefined
document.documentElement.scrollTop:0
document.body.scrollTop:100
Safari/Chrome:
window.pageYOffset:100
document.documentElement.scrollTop:0
document.body.scrollTop:100
Firefox/Opera:
doctype:
window.pageYOffset:100
document.documentElement.scrollTop:100
document.body.scrollTop:0
No doctype:
window.pageYOffset: 100
document.documentElement.scrollTop:0
document.body.scrollTop: 100
2. Get scrollTop value
Perfectly get scrollTop value assignment abbreviation: