Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery element.style的高度_Jquery_Css - Fatal编程技术网

jQuery element.style的高度

jQuery element.style的高度,jquery,css,Jquery,Css,如何获取由jQuery设置的DIV的高度? $('.bar2')。制作动画({'height':'58'+“%”,1500) 当我检查chrome中的元素时,我看到我的DIV height设置为58% 我想您应该使用: $(".bar2").outerHeight(); 哪一个是计算出的高度 $(".bar2").innerHeight(); 如果您不需要考虑边距和填充等因素。HTML: <div style="width: 200px; height: 200px; backgrou

如何获取由jQuery设置的DIV的高度?
$('.bar2')。制作动画({'height':'58'+“%”,1500)

当我检查chrome中的元素时,我看到我的DIV height设置为58%

我想您应该使用:

$(".bar2").outerHeight();
哪一个是计算出的高度

$(".bar2").innerHeight();
如果您不需要考虑边距和填充等因素。

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>
这里有一个活生生的例子-


只有当它真正改变时,你才能得到不同的高度。如果在请求调整大小后立即获取该元素,则会得到初始高度。

$。outerHeight()
将在返回值中包含该元素的边框和填充。不幸的是,您的答案。在您的示例中,高度将为50像素,因为它没有任何东西可以降低58%,所以最小高度将生效。我收回我的评论;在
上设置了高度后工作。
jQuery('.bar2').animate({'height':'58' + "%"}, 1500, function() {
    alert($(".bar2").css('height'))
});