-
-
Save overtrue/7f70a03a693e73e42736ff10ec66b4c6 to your computer and use it in GitHub Desktop.
js 获取页面滚动高度
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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