Alternatives to window.scrollMaxY?

前端 未结 4 560
你的背包
你的背包 2020-12-06 01:53

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

相关标签:
4条回答
  • 2020-12-06 02:44

    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.

    0 讨论(0)
  • 2020-12-06 02:44

    I've got away with document.body.scrollHeight so that

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

    at the end of the page (on Android).

    0 讨论(0)
  • 2020-12-06 02:47
     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
    
    0 讨论(0)
  • 2020-12-06 02:53

    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; 
    }
    
    0 讨论(0)
提交回复
热议问题