jQuery で高さを求める
$j('x').height() //border,padding,scrollbarを含まない高さ $j('x').attr('offsetHeight') //border,padding,scrollbarを含めた実際の高さ $j('x').attr('clientHeight') //paddingのみ含めた高さ $j('x').attr('scrollHeight') //clientHeightのtop位置(?)を起点にした中身の高さ
注意
$j('html').height()の結果が、FX1.5(Aptana) と IE6 で異なる
FX は中身の長さ(長い)、IE6 は見た目の長さ(短い)
中身の長さを取得する場合は、$j('html').attr('scrollHeight')とすること
テストソース
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <script src="../lib/jquery/jquery_1_2_6.js"> </script> <script> jQuery(function($j){ $j('.log1').html('<h5>outer box</h5>' + 'height : ' + $j('.a').height() + '<br/>' + 'offsetHeight : ' + $j('.a').attr('offsetHeight') + '<br/>' + 'clientHeight : ' + $j('.a').attr('clientHeight') + '<br/>' + 'scrollHeight : ' + $j('.a').attr('scrollHeight')) $j('.log2').html('<h5>inner box</h5>' + 'height : ' + $j('.b').height() + '<br/>' + 'offsetHeight : ' + $j('.b').attr('offsetHeight') + '<br/>' + 'clientHeight : ' + $j('.b').attr('clientHeight') + '<br/>' + 'scrollHeight : ' + $j('.b').attr('scrollHeight')) }) </script> <style> .a { margin: 100px; border: solid 10px blue; padding: 20px; width: 300px; height: 300px; overflow: scroll; } .b { background: #eee; margin: 30px; padding: 20px; border: solid 10px red; width: 500px; height: 500px; } .log1, .log2 { float: right; width: 150px; } </style> </head> <body> <div class="a"> <div class="b"> test </div> </div> <div class='log1'> </div> <div class='log2'> </div> </body> </html>