问题:我有一个固定宽度但未知(自动)高度的框(div)。
我需要使用 JQuery animate 函数打开/关闭该框。
问题是(在代码中也有注释)打开事件,我需要设置自动高度,这是我无法做到的。有人可以帮助将高度设置为自动吗?
JSFiddle: http: //jsfiddle.net/7m5Qa/ 代码如下:
HTML
<button id="open">open</button>
<button id="close">close</button>
<div id="textselector-body">
a<br/>
b<br/>
c<br/>
</div>
Java 脚本
$(document).ready(function(){
$("#open").click(function(){
$("#textselector-body").animate({
height:'100px' //here is problem. I need it 'auto'.
},2000);
});
$("#close").click(function(){
$("#textselector-body").animate({
height:'0'
},2000);
});
});