如何获得由jQuery设置的DIV高度?
$(‘.bar2’).animate({‘height’:’58’“%”},1500);
$(‘.bar2’).animate({‘height’:’58’“%”},1500);
当我检查chrome中的元素时,我看到我的DIV高度设置为58%
< div class =“bar2”style =“height:58%; background-image:......>
我试过这个:
var bar2 = $(“.bar2”).height()或var bar2 = $(“.bar2”).css(‘height’),
但我总是得到70分钟的“最小高度”,而不是jQuery设置的高度
解决方法
HTML:
<div style="width: 200px; height: 200px; background-color: blue;"> <div class="bar2" style="min-height: 70px; width: 100px; background-color: red;">foo</div> </div>
JS:
jQuery('.bar2').animate({'height':'58' + "%"},1500,function() { alert($(".bar2").css('height')) });
这里的实例 – http://jsfiddle.net/ANbrq/1/
实际更改时,您只能获得不同的高度.如果您在要求调整大小后尝试正确使用它,您将获得初始高度.