码迷,mamicode.com
首页 > 其他好文 > 详细

获取文档高度

时间:2014-07-16 23:08:48      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:android   style   blog   color   os   width   

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)
        };    
    };

 

获取文档高度,布布扣,bubuko.com

获取文档高度

标签:android   style   blog   color   os   width   

原文地址:http://www.cnblogs.com/qiangspecial/p/3811580.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!