私はdivの自動高さを取得しようとしています。通常、divボックスはcss 160pxを介して設定されますが、overflow: hidden; jquery経由で160px以上の自動高さを確認するにはどうすればよいですか?
私はボックスを持っているのでこれが必要です Show More または Show Less のボタンがあるので、高さが大きくない場合、コマンドを渡すために通常は高さ 160px です...今はボックスを小さくしています
私のコードはこれです:
<script type="text/javascript">
$("#Show_More_Websites").click(function() {
var Button_Value = $("#Show_More_Websites").attr("value");
var Box_Height = $('.Box_Show_Websites').outerHeight();
if(Button_Value == "Show More") {
if(Box_Height <= "160") {
var el = $('.Box_Show_Websites'),
curHeight = el.height(),
autoHeight = el.css('height', 'auto').height();
el.height(curHeight).animate({height: autoHeight}, 500);
}
$("#Show_More_Websites").attr('value', 'Show Less');
}
if(Button_Value == "Show Less") {
var el = $('.Box_Show_Websites'),
curHeight = el.height(),
autoHeight = el.css('height', '160px').height();
el.height(curHeight).animate({height: autoHeight}, 500);
$("#Show_More_Websites").attr('value', 'Show More');
}
});
</script>
アップデート
ここで私のコードを見つけることができます: http://jsfiddle.net/rAjBH/