window.scrollMaxY的替代?

问题描述 投票:10回答:4

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

javascript android webkit
4个回答
14
投票

替代window.scrollMaxY

document.documentElement.scrollHeight - document.documentElement.clientHeight

与DOC7PE XHTML 1.0 Transitional下的ie7,ie8,ff3.5,Safari 4,Opera 10,Google Chrome 3一样,给出了与window.scrollMaxY相同的结果。


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
投票

我已经离开了document.body.scrollHeight这样

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

在页面的末尾(在Android上)。


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
© www.soinside.com 2019 - 2024. All rights reserved.