Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternatives to window.scrollMaxY?

I' trying to use window.pageYOffset & window.scrollMaxY to calculate the current page progress. This approach works under FF3.5 but under webkit window.scrollMaxY is undefined.

like image 954
yanchenko Avatar asked Jul 07 '09 08:07

yanchenko


2 Answers

Alternative to window.scrollMaxY:

document.documentElement.scrollHeight - document.documentElement.clientHeight

gives same result as window.scrollMaxY with ie7, ie8, ff3.5, Safari 4, Opera 10, Google Chrome 3 under DOCTYPE XHTML 1.0 Transitional.

like image 140
panos Avatar answered Sep 21 '22 14:09

panos


two years later...

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; 
}
like image 30
nicolas Avatar answered Sep 19 '22 14:09

nicolas