我有一个菜单,其中每个项目都有通过ajax更新的内容(放在“内容”div中)。jQuery ajax不能动画div高度调整成功函数
在$.ajaxsuccess()功能,在这里我把AJAX中的“内容”分区接收到的数据,我想调整与动画的div高度()。这里的步骤:
得到旧的“内容”高度
更新“内容”分区与阿贾克斯接收到的数据
利用高差采取新的高度
动画。
所以我写了:
success : function (data) {
var contHeight = $("#content").height(); //older "content" height
$('#content').html(data); //update "content"
var diffHeight = $("#content").height() - contHeight; //difference from new and old height
$('#content').animate({height: '+=' + diffHeight + 'px'},500);
}
我想我的代码(使用调试一些alert()功能),我注意到:如果我使用animate(),contHeight它等于后的“内容”高度数据更新(旧的高度等于新的高度)并且没有动画。另一方面,如果我删除animate()旧的和新的高度是不同的。看起来animate()不允许更新“内容”高度。
+0
,这个问题很类似于你: [jQuery的动画高度](http://stackoverflow.com/questions/4603397/jquery-animate-height) –