【问题标题】:How to write jQuery animate when adding height添加高度时如何编写jQuery动画
【发布时间】:2018-04-29 21:54:20
【问题描述】:
CSS   
.bxspace{height: 258px;}    

jQuery
$('.bxspace').height( $('.bxspace').height() + 15 );

这是我的代码,具有获取bxspace 高度并在单击时添加15px 的功能。但我想在添加15px 时应用 animate() 使其平滑移动。在 qjQuery 下试过,但没有用。

var height = $('.bxspace').height( $('.bxspace').height() + 15 ); 
$('.bxspace').animate({height: height+'px'});

我是 jQuery 的新手,我不知道如何组合这两个代码。希望大家能给我一些建议。谢谢!

【问题讨论】:

    标签: jquery jquery-animate height


    【解决方案1】:

    您可以在animate() 中为接受数值的属性使用增量语法

    试试:

    $('.bxspace').animate({height: "+=15"});
    

    【讨论】:

    • 我明白了,没想过这个方法。其作品。谢谢。
    猜你喜欢
    • 2023-03-08
    • 2011-06-03
    • 1970-01-01
    • 2016-08-25
    • 2012-03-01
    • 2011-01-28
    • 1970-01-01
    • 2012-04-20
    • 2011-06-25
    相关资源
    最近更新 更多