隨筆-179  評論-666  文章-29  trackbacks-0


          var x = document.body.scrollLeft; 
          var y = document.body.scrollTop;

          //獲取屏幕寬度
             availWidth = parseInt(window.screen.availWidth);
             availHeight = parseInt(window.screen.availHeight);

          //獲取可見區(qū)域 寬度 高度
             availWidth = parseInt(document.body.clientWidth);
             availHeight = parseInt(document.body.clientHeight);
                  
          可見區(qū)域高度:document.body.clientHeight
          總高度:document.body.scrollHeight
          可見區(qū)域?qū)挾?document.body.clientWidth
          總寬度:document.body.scrollWidth

          ==============================================================

          var getWindowInfo=function()
          {
          var scrollX=0,scrollY=0,width=0,height=0,contentWidth=0,contentHeight=0;
          if(typeof(window.pageXOffset)=='number')
          {
           scrollX=window.pageXOffset;
           scrollY=window.pageYOffset;
          }
          else if(document.body&&(document.body.scrollLeft||document.body.scrollTop))
          {
           scrollX=document.body.scrollLeft;
           scrollY=document.body.scrollTop;
          }
          else if(document.documentElement&&(document.documentElement.scrollLeft||document.documentElement.scrollTop))
          {
           scrollX=document.documentElement.scrollLeft;
           scrollY=document.documentElement.scrollTop;
          }

          if(typeof(window.innerWidth)=='number')
          {
           width=window.innerWidth;
           height=window.innerHeight;
          }
          else if(document.documentElement&&(document.documentElement.clientWidth||document.documentElement.clientHeight))
          {
           width=document.documentElement.clientWidth;
           height=document.documentElement.clientHeight;
          }
          else if(document.body&&(document.body.clientWidth||document.body.clientHeight))
          {
           width=document.body.clientWidth;
           height=document.body.clientHeight;
          }

          if(document.documentElement&&(document.documentElement.scrollHeight||document.documentElement.offsetHeight))
          {
           if(document.documentElement.scrollHeight>document.documentElement.offsetHeight){
            contentWidth=document.documentElement.scrollWidth;
            contentHeight=document.documentElement.scrollHeight;
           }
           else
           {
            contentWidth=document.documentElement.offsetWidth;
            contentHeight=document.documentElement.offsetHeight;
           }
          }
          else if(document.body&&(document.body.scrollHeight||document.body.offsetHeight))
          {
           if(document.body.scrollHeight>document.body.offsetHeight)
           {
            contentWidth=document.body.scrollWidth;
            contentHeight=document.body.scrollHeight;
           }else{
            contentWidth=document.body.offsetWidth;
            contentHeight=document.body.offsetHeight;
           }
          }
          else
          {
           contentWidth=width;
           contentHeight=height;
          }
           if(height>contentHeight)
           height=contentHeight;
           if(width>contentWidth)
           width=contentWidth;
           var rect=new Object();
           rect.ScrollX=scrollX;
           rect.ScrollY=scrollY;
           rect.Width=width;
           rect.Height=height;
           rect.ContentWidth=contentWidth;
           rect.ContentHeight=contentHeight;
           return rect;
          }

          posted on 2007-05-25 13:34 Alpha 閱讀(9955) 評論(6)  編輯  收藏 所屬分類: JavaScript

          評論:
          # re: javascript 獲取窗口大小[未登錄] 2008-01-02 13:39 | aaa
          mark  回復  更多評論
            
          # re: javascript 獲取窗口大小 2008-07-03 10:50 | XU
          謝過~
          好東西啊。。。。。  回復  更多評論
            
          # re: javascript 獲取窗口大小 2009-07-20 11:37 | 周坤
          可以支持多瀏覽器,謝謝啦,呵呵。  回復  更多評論
            
          # re: javascript 獲取窗口大小[未登錄] 2010-09-02 13:57 | abc
          yes,henhao  回復  更多評論
            
          # re: javascript 獲取窗口大小[未登錄] 2010-11-10 15:57 | xx
          謝謝  回復  更多評論
            
          # re: javascript 獲取窗口大小 2012-04-22 16:40 | Joslin
          好東西啊!!!!!  回復  更多評論
            
          主站蜘蛛池模板: 黑龙江省| 安顺市| 布拖县| 贺兰县| 台东市| 湖口县| 大宁县| 钟祥市| 苗栗县| 德惠市| 伊金霍洛旗| 怀远县| 遂川县| 惠安县| 永新县| 凉城县| 三江| 会宁县| 疏附县| 乌海市| 武威市| 新密市| 昆山市| 得荣县| 繁昌县| 普格县| 金湖县| 筠连县| 社会| 周宁县| 安化县| 察隅县| 额尔古纳市| 巫山县| 莫力| 玛纳斯县| 满洲里市| 宁波市| 通山县| 璧山县| 贵港市|