軟件是對質(zhì)量的不懈追求

          scrollLeft,scrollWidth,clientWidth,offsetWidth完全詳解

          scrollHeight: 獲取對象的滾動高度。
          scrollLeft:設(shè)置或獲取位于對象左邊界和窗口中目前可見內(nèi)容的最左端之間的距離
          scrollTop:設(shè)置或獲取位于對象最頂端和窗口中可見內(nèi)容的最頂端之間的距離
          scrollWidth:獲取對象的滾動寬度
          offsetHeight:獲取對象相對于版面或由父坐標(biāo) offsetParent 屬性指定的父坐標(biāo)的高度
          offsetLeft:獲取對象相對于版面或由 offsetParent 屬性指定的父坐標(biāo)的計算左側(cè)位置
          offsetTop:獲取對象相對于版面或由 offsetTop 屬性指定的父坐標(biāo)的計算頂端位置
          event.clientX 相對文檔的水平座標(biāo)
          event.clientY 相對文檔的垂直座標(biāo)

          event.offsetX 相對容器的水平坐標(biāo)
          event.offsetY 相對容器的垂直坐標(biāo)
          document.documentElement.scrollTop 垂直方向滾動的值
          event.clientX+document.documentElement.scrollTop 相對文檔的水平座標(biāo)+垂直方向滾動的量

          以上主要指IE之中,F(xiàn)ireFox差異如下:
          IE6.0、FF1.06+:
          clientWidth = width + padding
          clientHeight = height + padding
          offsetWidth = width + padding + border
          offsetHeight = height + padding + border
          IE5.0/5.5:
          clientWidth = width - border
          clientHeight = height - border
          offsetWidth = width
          offsetHeight = height
          (需要提一下:CSS中的margin屬性,與clientWidth、offsetWidth、clientHeight、offsetHeight均無關(guān))

          測試代碼:

           

           

           

          測試代碼:

          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[url=http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd[/url]">
          <html xmlns="[url=http://www.w3.org/1999/xhtml]http://www.w3.org/1999/xhtml[/url]" lang="gb2312">
          <head>
          <head>
          <title> 代碼實例:關(guān)于clientWidth、offsetWidth、clientHeight、offsetHeight的測試比較 </title>
          <meta http-equiv="content-type" content="text/html; charset=gb2312" />
          <meta name="author" content="楓巖,CnLei.y.l@gmail.com">
          <meta name="copyright" content="[url=http://www.cnlei.com]http://www.cnlei.com[/url]" />
          <meta name="description" content="關(guān)于clientWidth、offsetWidth、clientHeight、offsetHeight的測試比較" />
          <style type="text/css" media="all">
          body {font-size:14px;}
          a,a:visited {color:#00f;}
          #Div_CnLei {
          width:300px;
          height:200px;
          padding:10px;
          border:10px solid #ccc;
          background:#eee;
          font-size:12px;
          }
          #Div_CnLei p {margin:0;padding:10px;background:#fff;}
          </style>
          <script type="text/javascript">
          function Obj(s){
          return document.getElementById(s)?document.getElementById(s):s;
          }
          function GetClientWidth(o){
          return Obj(o).clientWidth;
          }
          function GetClientHeight(o){
          return Obj(o).clientHeight;
          }
          function GetOffsetWidth(o){
          return Obj(o).offsetWidth;
          }
          function GetOffsetHeight(o){
          return Obj(o).offsetHeight;
          }
          </script>
          </head>
          <body>
          <p>點擊下面的鏈接:</p>
          <div id="Div_CnLei">
          <p><a href="javascript:alert(GetClientWidth('Div_CnLei'));">GetClientWidth();</a>  <a href="javascript:alert(GetClientHeight('Div_CnLei'));">GetClientHeight();</a></p>
          <p><a href="javascript:alert(GetOffsetWidth('Div_CnLei'));">GetOffsetWidth();</a>  <a href="javascript:alert(GetOffsetHeight('Div_CnLei'));">GetOffsetHeight();</a></p>
          </div>
          <div id="Description">
          <p><strong>IE6.0、FF1.06+:</strong><br />
          clientWidth = width + padding = 300+10×2 = 320<br />
          clientHeight = height + padding = 200+10×2 = 220<br />
          offsetWidth = width + padding + border = 300+10×2+10×2= 340<br />
          offsetHeight = height + padding + border = 200+10×2+10×2 = 240</p>
          <p><strong>IE5.0/5.5:</strong><br />
          clientWidth = width - border = 300-10×2 = 280<br />
          clientHeight = height - border = 200-10×2 = 180<br />
          offsetWidth = width = 300<br />
          offsetHeight = height = 200</p>
          </div>
          </body>
          </html>

          posted on 2009-11-14 14:12 BlakeSu 閱讀(162) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 保靖县| 抚宁县| 南城县| 出国| 平乐县| 堆龙德庆县| 开化县| 皋兰县| 天台县| 通海县| 盐山县| 沐川县| 阜新市| 策勒县| 桦南县| 漯河市| 湾仔区| 油尖旺区| 彭水| 赞皇县| 海宁市| 若尔盖县| 思茅市| 墨竹工卡县| 吴忠市| 白水县| 永德县| 柳林县| 塔城市| 衡阳市| 麻城市| 贵港市| 富源县| 喀喇沁旗| 虞城县| 永胜县| 石屏县| 修文县| 大邑县| 巩义市| 新乡县|