如何使用动画jquery

时间:2016-04-20 09:02:04

标签: javascript jquery html

有人可以帮助如何慢慢地将div打开到他的全尺寸;

我有什么:

使用HEIGHT 200px和overflow-y:hidden。

来规则div

按下按钮#showall我需要慢慢将#rules高度调到他的100%!!

我尝试了什么:

$("#showall").click(function(){
      $( "#rules" ).animate({
      height: "+=100px"
   }, 5000, function() {
      // Animation complete.
});

在我的例子中; + = 100px - 它的工作正常,但如果我换到高度:" 100%"它的开放div FAST没有动画

1 个答案:

答案 0 :(得分: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'); });