0

火狐:jsFiddle

我不确定这是否只是我的设置,但在 Firefox 中,在动画开始之前似乎有一点高度跳跃。

JavaScript:

window.run = function(){
var $alert = $('.alert').clone();                                    // Store for another run
var maxSize = 0;

$('#start-size').html($('.alert').height());                         // Default start size

$('.alert').slideUp({
  duration:1500,
  step: function(){ 
    var _height=$(this).height();
    if (_height>maxSize) {
      maxSize = _height;
      $('#max-size').html(maxSize);
    }
  },
  complete: function(){
    $(this).remove();
    setTimeout(function(){$('.container').append($alert);},1000);   // Reset for another run
  }
});

};

HTML:

<button onClick="run()">Slide Up</button>  
<div class="container">
  <div class="content alert">
    Alert! Hide
  </div>
</div>
<div>Start Size: <span id="start-size"></span></div>
<div>Max Size: <span id="max-size"></span></div>

CSS:

.container { border:1px solid black; margin:20px; padding: 5px; }
.content { border:1px solid #900; height:20px; padding:5px; }
.alert { background: #c99; color: #900; }
4

2 回答 2

0

似乎如果您在动画之前设置最大高度,它将修复它。

var $alert = $('.alert');
$alert.css('max-height',$alert.height()).slideUp({...});

但是,我还没有找到为什么会这样。

于 2013-01-17T23:33:11.680 回答
0

尝试为 height 属性设置动画,而不是使用该slideUp()方法。

于 2013-01-18T02:59:12.637 回答