Jquery 如何设置从动态值到其动态高度值的div高度动画?
我想对第一个div使用slideDown()的效果来显示它,从动态生成的最后一个div的高度开始,到由其内部内容动态生成的高度 在下面的代码中,出现问题的部分是.animate({'height':'200px'}/.animate({'height':'100px'}),应该动态生成值200px和100pxJquery 如何设置从动态值到其动态高度值的div高度动画?,jquery,jquery-animate,Jquery,Jquery Animate,我想对第一个div使用slideDown()的效果来显示它,从动态生成的最后一个div的高度开始,到由其内部内容动态生成的高度 在下面的代码中,出现问题的部分是.animate({'height':'200px'}/.animate({'height':'100px'}),应该动态生成值200px和100px <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> &l
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Slide Down</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style type="text/css">
div {background:#de9a44;width:80px; }
</style>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
<div style="display: none">
In pellentesque risus sit amet magna consectetur nec consequat eros ornare.
</div>
<div>Vivamus placerat eleifend rutrum</div>
Click!
<script type="text/javascript">
$(document.body).click(function () {
if ($("div:first").is(":hidden")) {
var height = $("div:last").height();
$("div:last").hide();
$("div:first").height(height);
$("div:first").animate({'height':'200px'},"slow");
} else {
var height = $("div:first").height();
$("div:first").hide();
$("div:last").height(height);
$("div:last").animate({'height':'100px'},"slow");
}
});
</script>
</body>
</html>
滑落
div{背景:de9a44;宽度:80px;}
在佩伦茨克的圣殿里,坐着一位伟大的圣者,他为厄洛斯·奥纳雷祈祷。
马蹄莲
点击
$(document.body)。单击(函数(){
如果($(“div:first”).是(“:hidden”)){
变量高度=$(“div:last”).height();
$(“div:last”).hide();
$(“div:first”)。高度(height);
$(“div:first”).animate({'height':'200px'},“slow”);
}否则{
变量高度=$(“div:first”).height();
$(“div:first”).hide();
$(“div:last”)。高度(height);
$(“div:last”).animate({'height':'100px'},“slow”);
}
});
尝试以下方法:
$("div:last").animate({'height':'auto'},"slow");
找到了答案。我不知道你能得到隐藏元素的维度,解决方案自然就来了
<script type="text/javascript">
$(document.body).click(function () {
if ($("div:first").is(":hidden")) {
var hidden = $("div:first").height();
var showing = $("div:last").height();
$("div:last").hide();
$("div:first").height(showing);
$("div:first").animate({'height':hidden},"slow");
} else {
var hidden = $("div:last").height();
var showing = $("div:first").height();
$("div:first").hide();
$("div:last").height(showing);
$("div:last").animate({'height':hidden},"slow");
}
});
</script>
$(document.body)。单击(函数(){
如果($(“div:first”).是(“:hidden”)){
var hidden=$(“div:first”).height();
显示变量=$(“div:last”).height();
$(“div:last”).hide();
$(“div:first”)。高度(显示);
$(“div:first”).animate({'height':hidden},“slow”);
}否则{
var hidden=$(“div:last”).height();
显示变量=$(“div:first”).height();
$(“div:first”).hide();
$(“div:last”)。高度(显示);
$(“div:last”).animate({'height':hidden},“slow”);
}
});
不适用于“高度”:“自动”
另外,我是AlqQ。我想我是前一段时间注册的,现在当我使用OpenID登录时,它会将我重定向到这个旧帐户,这对我来说很好。目标高度应该从哪里来?