2016-04-20 23 views
1

有人可以帮助如何缓慢打开div到他的全尺寸;如何使用动画缓慢地打开div jquery

我有:

规则随高度200像素和溢出-Y DIV:隐藏。

当按下按钮#showall我需要慢慢使#rules身高达到他的100%!

我的尝试:

$("#showall").click(function(){ 
     $("#rules").animate({ 
     height: "+=100px" 
    }, 5000, function() { 
     // Animation complete. 
}); 
在我的例子高度

; + = 100像素 - 它的正常工作,但如果我改变高度: “100%” 的开放DIV FAST没有动画

回答

3

使用了slideDown:

$("#showall").click(function(){ 
    $("#rules").slideDown(5000, function() { 
    // Animation complete. 
    }); 
}); 

尝试这种新的解决方案:

$this= $("#rules"); 
var currentHeight = $this.height(); 
     autoHeight = $this.css('height', 'auto').height() 
     $this.data('height', currentHeight) 
      .height(currentHeight).animate({ 
             height: autoHeight}, 
             200, 
             function() { $(this).addClass('open'); }); 
+0

错误的东西..不工作..不打开div到他的全尺寸。我重复。 #showall有CSS属性height:200px;溢出-γ:隐藏;我需要打开到全尺寸(100%);它可能是598像素或400像素或等 – WhoIsDT

+0

尝试新的解决方案,我编辑后在 –

+0

令人惊叹!非常感谢!!加工! – WhoIsDT