jQuery';s.slideDown/Up()手柄滑动到未知(自动)高度?

jQuery';s.slideDown/Up()手柄滑动到未知(自动)高度?,jquery,html,css,animation,height,Jquery,Html,Css,Animation,Height,我想向下滑动(显示)这个具有0px高度的DIV: 。。。各种内容 但是,由于各种屏幕宽度、字体大小和其他影响内部布局的因素,最终高度未知,因此无法确定目标高度 如果我必须手动操作,我会用可见性:hidden显示它,测量高度,然后将其设置为已知高度的动画(不过,这也有缺点) 我在文档中使用jQuery的.slideDown(),但在这种特殊情况下对我不起作用 jQuery如何知道最终高度? 编辑:一种解决方法是使用另一个内部div,其高度为height:auto将用于测量高度。您应该获得其中元素的

我想向下滑动(显示)这个具有
0px
高度的DIV:

。。。各种内容

但是,由于各种屏幕宽度、字体大小和其他影响内部布局的因素,最终高度未知,因此无法确定目标高度

如果我必须手动操作,我会用
可见性:hidden显示它
,测量高度,然后将其设置为已知高度的动画(不过,这也有缺点)

我在文档中使用jQuery的
.slideDown()
,但在这种特殊情况下对我不起作用

jQuery如何知道最终高度?

编辑:一种解决方法是使用另一个内部div,其高度为
height:auto将用于测量高度。

您应该获得其中元素的.height(),将这些元素相加,并使div的高度等于height:)


这是个老问题。我原来是在寻找同一个问题的答案,你的编辑正是我在寻找的


希望这能帮助任何人解决同样的问题。

这不是答案,但如果您想知道jQuery函数是如何工作的:这是一个非常弱的解决方案,因为存在浮点数。
$("a#moreRequests").on("click", function(){// click this and the div grows

//console.log("this hits");
var friends = $(".friendsDiv");
var divHeight = $(".auto").height();

if(friends.hasClass("grow")){// if the div has the class grow on it, then shrink
  friends.animate({
    height: "100px"
  },1000, function(){
    console.log("this is if it has the class .grow,");
  }).removeClass("grow");
} 
else{
  friends.animate({
    height: divHeight
  },1000, function(){
    console.log("this is if it doesn't has the class .grow div height: " + divHeight);
  }).addClass("grow");
}
return false;
});