Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
js 获取页面滚动高度
var scrollTop = window.pageYOffset
|| document.documentElement.scrollTop
|| document.body.scrollTop
|| 0;
var scrollLeft = window.pageXOffset // netscape
|| document.documentElement.scrollLeft
|| document.body.scrollLeft
|| 0;
document.body对象必须在 body 内容加载完才有值,而document.documentElement 对象则在访问时就存在了. 当遵循标准时如果要访问body对象时document.body就会失效,相反 document.documentElement 就会失效。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.