0

我有一个当前调整 div 大小的代码,它可以工作,但是它只会稍微调整 div 的大小,我不确定如何编辑代码以使 div 调整为特定大小!

非常感谢任何帮助!

<script type="text/javascript">
$(document).ready(function(){    
$(".expanderHead").click(function(){
    var $exsign = $("#expanderSign");
    $(this).find("#expanderContent").slideToggle();
    $exsign.html($exsign.text() == '+' ? '-': '+');   
    // simplify your if/else into one line using ternary operator
    // if  $exsign.text() == "+" then use "-" else "+"
    });    
 });
 </script>
4

1 回答 1

2

instead of this:

$(this).find("#expanderContent").slideToggle();

do this:

$(this).find("#expanderContent").animate({height: '50px'});

Update

See the jsfiddle: http://jsfiddle.net/csQYN/

As pointed by @JonathanSampson, slideToggle() will also save the previous state (the one to toggle back to). You you animate, you should be responsible to implement that.

于 2012-09-25T18:51:37.297 回答