获取文档高度

var Browser = (function(){

          var na = window.navigator,

               ua = na.userAgent.toLowerCase(),

               browserTester = /(msie|webkit|gecko|presto|opera|safari|firefox|chrome|maxthon|android|ipad|iphone|webos|hpwos)[ \/os]*([\d_.]+)/ig,

               Browser = {

                    platform: na.platform

               };

          ua.replace(browserTester, function(a, b, c) {

               var bLower = b.toLowerCase();

               if (!Browser[bLower]) {

                    Browser[bLower] = c; 

               }

          });

          if (Browser.opera) { //Opera9.8后版本号位置变化

               ua.replace(/opera.*version\/([\d.]+)/, function(a, b) {

                    Browser.opera = b;

               });

          }

          if (Browser.msie) {

               Browser.ie = Browser.msie;

               var v = parseInt(Browser.msie, 10);

               Browser['ie' + v] = true;

          }

          return Browser;

     })();



var getDocRect = function(doc){

        doc = doc || document;



        var win = doc.defaultView || doc.parentWindow,

            mode = doc.compatMode,

            root = doc.documentElement,

            h = win.innerHeight || 0,

            w = win.innerWidth || 0,

            scrollX = win.pageXOffset || 0,

            scrollY = win.pageYOffset || 0,

            scrollW = root.scrollWidth,

            scrollH = root.scrollHeight,

            offsetW,offsetH;



        if (mode != 'CSS1Compat') { // Quirks

            root = doc.body;

            scrollW = root.scrollWidth;

            scrollH = root.scrollHeight;

        }



        if (mode && !Browser.opera) { // IE, Gecko

            w = root.clientWidth;

            h = root.clientHeight;

        }



        scrollW = Math.max(scrollW, w);

        scrollH = Math.max(scrollH, h);



        scrollX = Math.max(scrollX, doc.documentElement.scrollLeft, doc.body.scrollLeft);

        scrollY = Math.max(scrollY, doc.documentElement.scrollTop, doc.body.scrollTop);

        offsetW =document.body.offsetWidth||document.documentElement.offsetWidth;

        offsetH = document.body.offsetHeight||document.documentElement.offsetHeight;

        return {

            width: w,

            height: h,

            scrollWidth: scrollW,

            scrollHeight: scrollH,

            scrollX: scrollX,

            scrollY: scrollY,

            contentWidth:(scrollW == w ? offsetW:scrollW),

            contentHeight:(scrollH == h ? offsetH:scrollH)

        };    

    };

 

你可能感兴趣的:(获取)