2009-07-07 16 views
9

Próbuję użyć window.pageYOffset & window.scrollMaxY do obliczenia postępu bieżącej strony. To podejście działa w trybie FF3.5, ale pod Windowkit window.scrollMaxY jest niezdefiniowany.Alternatywy dla window.scrollMaxY?

Odpowiedz

2

Mam sucho document.body.scrollHeight tak że

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

na końcu strony (na Androida).

14

Alternatywa window.scrollMaxY:

document.documentElement.scrollHeight - document.documentElement.clientHeight 

daje taki sam wynik jak window.scrollMaxY z IE7, IE8, ff3.5, Safari 4, Opera, Google Chrome 10 3 pod DOCTYPE XHTML 1.0 Transitional.

+0

Dziękuję dobrą sir. Chciałbym wiedzieć, czy są jakieś minusy w używaniu tej metody. Właśnie testowałem to w chrome/firefox i działa! – swajak

+0

Próba zaimplementowania go przeciwko 'window.scrollY' zauważyłem, że w chrome przynajmniej' window.scrollY' jest wysoce precyzyjnym floatem, a 'scrollHeight' i' clientHeight' są liczbami całkowitymi, więc musiałem "Math.round"() 'to – Kaiido

3

dwa lata później ...

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