隨筆-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 閱讀(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
          好東西啊!!!!!  回復  更多評論
            
          主站蜘蛛池模板: 永修县| 孝昌县| 中卫市| 项城市| 塔城市| 江北区| 荣昌县| 鄂托克前旗| 左云县| 项城市| 德令哈市| 濉溪县| 马公市| 黎城县| 安徽省| 上饶市| 鄢陵县| 宜丰县| 诏安县| 鹿邑县| 龙海市| 襄汾县| 津南区| 赫章县| 蓬莱市| 镇原县| 公安县| 乌拉特前旗| 娱乐| 会同县| 普兰店市| 昌宁县| 红桥区| 太仓市| 镇坪县| 承德市| 固始县| 荔波县| 乐亭县| 乌拉特后旗| 泰顺县|