jquery - 最后显示 div 顶部的 slideUp

标签 jquery html css slide

jQuery 的 slideDownslideUp 函数非常方便,但我需要稍微改变一下它们的行为。

它的作用

当您在 div 上调用 slideDown 时,通常发生的情况是 div 向下滑动,并且随着它进一步向下滑动,div 的下方内容 被揭示。

我需要它做什么

我想让 div 向下滑动,但是应该显示上面的内容,而不是显示 div 的下面的内容。所以最底部的内容应该首先可见,然后上面的内容应该滑入 View 。这样做的目的是让 div 看起来像是从屏幕外滑到屏幕上。这是一个图表:

How it works now:
----------
| Line 1 | |  Reveals from top to bottom; top is anchored in place
| Line 2 | |  As the div expands vertically, Line 1 is shown first and
| Line 3 | |  none of the lines move as they become visible.
********** V
| Line 4 | 
| Line 5 |
----------

How I would like it to work:
----------
| Line 1 |    
| Line 2 |    
| Line 3 |    
********** ^  Reveals from bottom to top; bottom is anchored in place
| Line 4 | |  As the div expands vertically, the Line 5 is shown first and
| Line 5 | |  moves downward as more is revealed.
----------

我意识到我可能没有有效地沟通,如果您需要更多说明,请告诉我。

更新:

这是与我正在使用的等效的 HTML:

<div id="anchored">
    <table>
        <tr>
            <td>
                <!-- this is the div that is initially invisible and should slide from the bottom -->
                <div id="slider">
                    hello
                </div>
            </td>
        </tr>
        <tr>
            <td>
            <!-- this is always visible and should be pushed down by "slider" as it moves downward -->
            hello 
            </td>
        </tr>
    </table>
</div>

CSS:

#anchored {
    position: fixed;
    top: 0px;
}

#slider {
    display: none;
}

table {
    width: 100%;
}

最佳答案

我建议类似于以下内容,但鉴于您尚未显示您的 HTML,这只能是一个建议(而不是具体的答案,但如果您发布您的实际 HTML,那么我可以尝试提供一些东西这样会更好):

var container = $('#slide'),
    p = container.find('p');

container.height(p.height());
$(p).css({
    'position' : 'absolute',
    'top' : -p.height()
}).animate({
    'top' : 0
},2500);

JS Fiddle demo .

HTML:

<div id="slide">
<p><!-- contents... --></p>
</div>​

CSS:

#slide {
    border: 1px solid #000;
    position: relative;
    overflow: hidden;
}​

引用资料:

  1. jQuery:

  2. CSS:

关于jquery - 最后显示 div 顶部的 slideUp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10092141/

相关文章:

带有事件类的 jQuery 切换

jQuery:动画移除 CSS 属性

javascript - 在光标不移动时更改光标

javascript - jQuery 和 Prototype 目前的区别是什么?

jQuery onClick 导航选项卡 - 需要拉入正文内容

php - 没有表格就提交表格

html - 我无法将 <td> 中的复选框和单选按钮居中

javascript - 加载时的图像幻灯片无法正常工作

html - 固定页眉仅在一页上

css - 如何在 Liferay 的 Vaadin portlet 中管理样式