2016-04-20 22 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