window.scrollMaxY的替代?

时间:2009-07-07 08:36:47

标签: javascript android webkit

我想尝试使用 window.pageYOffset & window.scrollMaxY 计算当前页面进度。这种方法在FF3.5下工作,但在webkit window.scrollMaxY 下是未定义的。

4 个答案:

答案 0 :(得分:14)

window.scrollMaxY的替代方案:

document.documentElement.scrollHeight - document.documentElement.clientHeight

window.scrollMaxY的结果与ie7,ie8,ff3.5,Safari 4,Opera 10,Google Chrome 3在DOCTYPE XHTML 1.0 Transitional下的结果相同。

答案 1 :(得分:3)

两年后......

function getScrollMaxY(){"use strict";
    var innerh = window.innerHeight || ebody.clientHeight, yWithScroll = 0;

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

答案 2 :(得分:2)

我已经离开了document.body.scrollHeight以便

document.body.scrollHeight = window.pageYOffset + screen height in pixels
页面末尾的

(在Android上)。

答案 3 :(得分: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