jquery动画(100%元素高度) [英] jquery animate down (100% element height)

查看:296
本文介绍了jquery动画(100%元素高度)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做的事情只需使用:

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

 slideDown("fast");

但是,我不喜欢如何显示元素,我想它是100 %的元素原始高度,并向下滚动。我想知道是否有一个简单的方法这样做?

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.

我想做的例子:
http://jsfiddle.net/7dary/1/
但是我想让它只是做所有的自动计算,如果它在页面底部,则不会显示在页面中间。我自己为其分配了-200像素或其他内容。

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.

推荐答案

解决方案:

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); 

链接: http://jsfiddle.net/MattLo/7dary/2/

这篇关于jquery动画(100%元素高度)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆