隨筆-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);

          //獲取可見區域 寬度 高度
             availWidth = parseInt(document.body.clientWidth);
             availHeight = parseInt(document.body.clientHeight);
                  
          可見區域高度:document.body.clientHeight
          總高度:document.body.scrollHeight
          可見區域寬度: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 閱讀(9971) 評論(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
          好東西啊!!!!!  回復  更多評論
            
          主站蜘蛛池模板: 大足县| 大兴区| 嫩江县| 彭水| 开原市| 获嘉县| 江阴市| 安顺市| 苍溪县| 澎湖县| 绩溪县| 通渭县| 永修县| 禹州市| 慈利县| 綦江县| 双鸭山市| 城口县| 长兴县| 金沙县| 临清市| 衡山县| 上思县| 疏附县| 阳江市| 屏山县| 沧州市| 临猗县| 连江县| 垦利县| 宜丰县| 永济市| 松原市| 城固县| 乌恰县| 陵川县| 普格县| 罗江县| 贺兰县| 钦州市| 金山区|