window.scrollMaxY的替代品?

我试图使用window.pageYOffsetwindow.scrollMaxY来计算当前页面的进度。 这种方法在FF3.5下工作,但在webkit 窗口下.scrollMaxY未定义。

Solutions Collecting From Web of "window.scrollMaxY的替代品?"

替代window.scrollMaxY:

document.documentElement.scrollHeight – document.documentElement.clientHeight

在DOCTYPE XHTML 1.0 Transitional下给出了和ie7,ie8,ff3.5,Safari 4,Opera 10,Google Chrome 3一样的window.scrollMaxY。

两年后…

 function getScrollMaxY(){ var innerh; if (window.innerHeight){ innerh = window.innerHeight; }else{ innerh = document.body.clientHeight; } if (window.innerHeight && window.scrollMaxY){ // Firefox yWithScroll = window.innerHeight + window.scrollMaxY; } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac yWithScroll = document.body.scrollHeight; } else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari yWithScroll = document.body.offsetHeight; } return yWithScroll-innerh; } 

我已经拿走了document.body.scrollHeight

 document.body.scrollHeight = window.pageYOffset + screen height in pixels 

在页面的结尾处(在Android上)。

  x = document.body.clientHeight; console.log(x ,"Cline HEight"); xx = window.innerHeight; console.log(xx, "Inner Height"); xxx = document.body.scrollHeight console.log(xxx, "scrollHeight"); xxxx = window.scrollMaxY; console.log(xxxx, "scrollMaxY for IE"); xxxxx = document.body.offsetHeight; console.log(xxxxx, "offsetHeight"); xxxxxx= document.body.scrollTop; console.log(xxxxxx, "scrollTop");strong text