2013-02-11 48 views
1

的高度我有这样的功能:jQuery的:动画到DIV

function fixedFeeSize(i){ 
    var num1 = $('#num' + i); 
    if (num1.hasClass("extended")) { 
     num1.stop(true, true).animate({height: '59px'},500); 
     num1.removeClass("extended"); 
    }else{ 
     var height = 0; 
     num1.animate({height: '360px'},500); 
     num1.addClass("extended"); 
    } 
    return null; 
} 

哪个扩张/收缩一个div,但我很努力得到它扩大到div每个div的高度(会有10+)将会有不同的高度。

我试过num1.animate({height: 'auto'},500);没有工作。

+2

[JavaScript jQuery Animate to Auto Height]的可能重复(http://stackoverflow.com/questions/5003220/javascript-jquery-animate-to-auto-height) – techfoobar 2013-02-11 16:37:09

+0

请提供jsfiddle示例 – Dom 2013-02-11 17:30:03

回答

1

这是你所追求的效果吗?

jQuery(".menu a").mouseenter(function(){ 
    jQuery(this).stop().animate({ 
    height: 200, opacity: 0.5 
}, 1000, "linear"); 
}); 
jQuery(".menu a").mouseleave(function(){ 
    jQuery(this).stop().animate({ 
    height: 18, opacity: 1 
}, 1000, "linear"); 
}); 

这里有一个的jsfiddle: http://jsfiddle.net/kKAZx/1/

对于进一步的阅读,看看在.animate功能的完整文档:

您可以结合效果,使各种奇妙,符合标准的效果。