【问题标题】:jQuery special div height animationjQuery 特殊 div 高度动画
【发布时间】:2012-11-15 06:01:49
【问题描述】:

有没有办法通过允许 div 的顶部和底部展开来在 jQuery 中设置 div 高度的动画?我想在 LDS 主页上做类似的事情:www.lds.org。顶部横幅图像左侧的 div 是我想要的类型。

【问题讨论】:

    标签: jquery html jquery-animate height


    【解决方案1】:

    您可以通过将 div 向上移动同时为其高度设置动画来创建它向上和向下方向扩展的错觉。

    <html>
    
    <head>
    <script type="text/javascript" src="jquery-1.8.0.min.js"></script>
    <script>
    $(document).ready( function() {
        var d = $('div');
        d.css('top', '250px').css('height', 0);
        d.animate( {
            height: '500px',
            top: 0
        } , 3000 );
    } );
    </script>
    <style>
    div {
        width: 500px;
        height: 500px;
        background: #f00;
        position: absolute;
    }
    </style>
    </head>
    
    <body>
    <div></div>
    </body>
    
    </html>
    

    【讨论】:

    • 谢谢!你能告诉我为什么必须将职位声明为绝对职位吗?
    猜你喜欢
    • 2023-03-14
    • 2011-06-03
    • 1970-01-01
    • 1970-01-01
    • 2010-11-29
    • 2016-08-25
    • 2012-03-01
    • 2019-07-13
    • 1970-01-01
    相关资源
    最近更新 更多