CSS/Javascript通过动画切换高度?

CSS/Javascript通过动画切换高度?,javascript,jquery,Javascript,Jquery,我需要将全高切换到定义的高度,这是我当前的代码: <div style="height: 20px; overflow: hidden; display: block;" onclick="if (this.style.height == '20px') { $(this).animate({height:'auto'} } else { $(this).animate({height:'20px'}); }"> 问题在于: $(此).animate({height:'auto

我需要将全高切换到定义的高度,这是我当前的代码:

<div style="height: 20px; overflow: hidden; display: block;" onclick="if (this.style.height == '20px') { $(this).animate({height:'auto'} } else { $(this).animate({height:'20px'}); }">

问题在于:

$(此).animate({height:'auto'}
-将动画设置为'auto'高度不起作用

使用普通JS
this.style.height='auto'
可以:


我如何用jQuery设置动画或在javascript中添加动画?(在JS或CSS上)我知道问题在于设置未知高度的动画,是否有办法获得完整高度?或者idk,如何解决这个问题?

这里有一个animateAuto插件,它解决了
.animate()的这个限制
API: