Prototype-element-getdimensions

提供:Dev Guides
移動先:案内検索

プロトタイプ-getDimensions()メソッド

このメソッドは、計算された要素の幅と高さを見つけ、それらをオブジェクトのキー/値のペアとして返します。

このメソッドは、インラインスタイルルールまたはCSSスタイルシートで表示がnoneに設定されている要素の正しい値を返します。

返される値は数値であることに注意してください。ただし、ピクセル単位で表されます。

構文

element.getDimensions();

戻り値

オブジェクト\ {height:Number、width:Number}のキー/値のペアを返します。

<html>
   <head>
      <title>Prototype examples</title>
      <script type = "text/javascript" src = "/javascript/prototype.js"></script>

      <script>
         function showResult() {
            var dimensions = $('rectangle').getDimensions();
            alert("Element width is " +  dimensions.width );
            alert("Element height is " +  dimensions.height );
         }
      </script>
   </head>

   <body>
      <p>Click the button to see the result.</p>

      <div id = "rectangle"
         style = "font-size: 10px; width: 20em; height: 10em">
         <p>This is the paragraph.</p>
      </div>
      <br/>

      <input type = "button" value = "showResult" onclick = "showResult();"/>
   </body>
</html>

出力