Skip to content

Instantly share code, notes, and snippets.

Embed
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.documentElement何時使用。當HTML頭部引用了W3C標準,在标准里没有document.body這個对象,這時就需要document.documentElement來代替。
document.body对象必须在 body 内容加载完才有值,而document.documentElement 对象则在访问时就存在了. 当遵循标准时如果要访问body对象时document.body就会失效,相反 document.documentElement 就会失效。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
*/
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.