jquery animate down(100%元素高度)

时间:2012-01-22 06:41:22

标签: javascript jquery css jquery-animate slidedown

我想要做的只是使用:

 slideDown("fast");

然而,我不喜欢它如何揭示元素,我想它是100%的元素原始高度,并滚动下来。我想知道是否有一种简单的方法可以做到这一点?除了可能更改margin-top等之外,然后将其设置为恢复正常。

我想做的例子: http://jsfiddle.net/7dary/1/ 但是我想让它自动完成所有的计算,如果它位于页面底部并且我个人分配了-200px或其他东西,它就不会显示在页面中间。

1 个答案:

答案 0 :(得分:4)

解决方案:

var $element = $("#itemToSlide"); // make sure its visible
var height = $element.height(); // get the height when its populated
$element.css({marginTop:height*-1}); // set it to 0 with an overflow hidden

// trigger the animate now or later in an event
$element.show().animate({marginTop:0},2200); 

link:http://jsfiddle.net/MattLo/7dary/2/

相关问题