jquery animate down (100% element height)

☆樱花仙子☆ 提交于 2019-12-11 11:08:51

问题


What I want to do can be accomplished just by using:

 slideDown("fast");

However, I don't like how it reveals the element, I would like for it to be 100% of the elements original height, and roll down. I'm wondering if there's an easy way of doing this? Other than perhaps changing the margin-top and such, then animating it back to normal.

Example of what I want to do: http://jsfiddle.net/7dary/1/ However I would like to have it just do all of the calculations automatically, and it not show in the middle of the page if it's at the bottom of the page and I personally assign -200px or something to it.


回答1:


Solution:

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/



来源:https://stackoverflow.com/questions/8959518/jquery-animate-down-100-element-height

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!