我想切换分区的高度。我尝试过将 .animate 与 if/else 语句一起使用。但它只会反弹。
我现在使用的代码将隐藏我的分区而不是切换高度。点击时会触发。
$(document).ready(function() {
$("#content1").toggle(function(){
$(this).animate({height:'400px'});
}, function() {
$(this).animate({height:'200px'});
});
});
我希望有人能找到答案,因为我在 google/stackoverflow 上找不到答案。
你为什么不使用.animate()
直接设置 div 的高度并在每次单击 div 时为更改设置动画!
like:
$( "div" ).click(function() {
if ( $(this).height() != 50)
$( this ).animate({ height: 50 }, 1000 );
else
$( this ).animate({ height: 100 }, 1000 );
});
这是一个完整的例子:http://jsfiddle.net/62jcH/3/ http://jsfiddle.net/62jcH/3/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)