如何使用 auto 而不是固定数字来为 div 类设置动画?
对于我的生活,我无法弄清楚这一点,我试图将 div 动画到其自然高度,但是 jquery 只让我下降值。我希望根据内容量自动调整大小...我遇到问题的代码中的行是:
$elem.addClass('current').animate({height: '100'},300) ;
我想要 100 是自动的。请帮忙!
这是代码:
$list.find('.st_arrow_down').live('click',function(){
var $this = $(this);
hideThumbs();
$this.addClass('st_arrow_up').removeClass('st_arrow_down');
var $elem = $this.closest('li');
var $plus = $this.closest('li').height();
$elem.addClass('current').animate({height: '100'},300);
var $thumbs_wrapper = $this.parent().next();
$thumbs_wrapper.show(200);
});
$list.find('.st_arrow_up').live('click',function(){
var $this = $(this);
$this.addClass('st_arrow_down').removeClass('st_arrow_up');
hideThumbs();
});
for the life of me I cannot figure this out, I am trying to animate a div to its natural height, however jquery only lets me drop in values. I would like this to auto size depending on the amount of content...the line in the code I am having trouble with is:
$elem.addClass('current').animate({height: '100'},300);
I would like 100 to be auto. PLEASE HELP!
Here is the code:
$list.find('.st_arrow_down').live('click',function(){
var $this = $(this);
hideThumbs();
$this.addClass('st_arrow_up').removeClass('st_arrow_down');
var $elem = $this.closest('li');
var $plus = $this.closest('li').height();
$elem.addClass('current').animate({height: '100'},300);
var $thumbs_wrapper = $this.parent().next();
$thumbs_wrapper.show(200);
});
$list.find('.st_arrow_up').live('click',function(){
var $this = $(this);
$this.addClass('st_arrow_down').removeClass('st_arrow_up');
hideThumbs();
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你是说计算高度?
如果您使用 CSS 为 $elem 设置了固定高度,则这将不起作用。
You mean computed height?
This won’t work if you have a fixed height set for $elem using CSS.
我看到的唯一可能性是克隆节点(删除固定高度),将其放置在屏幕外的某个位置,然后测量它。
The only possibility I see is to clone the node (remove the fixed height), place it somewhere offscreen, and measure it.