我试图使用window.pageYOffset&window.scrollMaxY来计算当前页面进度。这种方法在FF3.5下工作,但在webkit window.scrollMaxY下是未定义的。
替代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
相同的结果。
两年后......
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;
}
我已经离开了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