在标准模式下,即文档头部有 doctype 声明,浏览器滚动条是属于 html 元素的,只能通过 document.documentElement.scrollTop 获取滚动距离。
doctype
document.documentElement.scrollTop
在怪异模式下,即文档头部没有 doctype 声明,浏览器滚动条数属于 body,通过 document.body.scrollTop 获取滚动距离。
document.body.scrollTop