2009-07-07 5 views
9

私はwindow.pageYOffset & window.scrollMaxYを使用して現在のページの進行状況を計算しようとしています。このアプローチはFF3.5で動作しますが、Webkit window.scrollMaxYは未定義です。window.scrollMaxYの代替品ですか?

答えて

2

私は(Android上)ページの最後にdocument.body.scrollHeight

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

ように離れて持っています。 window.scrollMaxY

14

オルタナティブ:

document.documentElement.scrollHeight - document.documentElement.clientHeight 

は暫定DOCTYPEをXHTML 1.0の下でIE7、IE8とwindow.scrollMaxY、ff3.5、サファリ4、オペラ10、Google Chromeの3と同じ結果になります。

+0

はあなたに良い先生に感謝します。私は、この方法を使うことには何か欠点があるかどうかを知りたいです。私はchrome/firefoxでそれをテストして、うまくいきます! – swajak

+0

これを 'window.scrollY'に対して実装しようとしました。クロムで少なくとも' window.scrollY'は高精度floatですが、 'scrollHeight'と' clientHeight'は整数なので、 'Math.round () 'それ – Kaiido

3

2年後...

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; 
} 
0
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