【问题标题】:Bootstrap alert boxes height animation with Zepto jumpy带有 Zepto 跳跃的引导警报框高度动画
【发布时间】:2014-05-04 03:35:42
【问题描述】:

我正在尝试在用户单击关闭按钮时平滑地隐藏 Bootstrap 警报框。然而,Zepto 使警报框以一种非常奇怪的方式运行:

我正在使用以下代码来处理关闭:

$(".alert .close").click(function(){
    $(this).parent().animate({"height": "0px"}, 400, function(){
        this.hide().css("height", "");
    });
})

这是一个小提琴:http://jsfiddle.net/ascom/HWaNj/

如何使警报框动画流畅?

更新: 将 height:0 添加到警告框使其看起来像这样:

这可能意味着 Bootstrap 中的某些东西使盒子表现得像这样。

【问题讨论】:

    标签: javascript twitter-bootstrap animation zepto


    【解决方案1】:

    这似乎与缺少预定义的高度和溢出有关。此外,margin 和 padding 的使用也会扭曲动画。看看这个作为一个工作示例。

    $(".alert .close").click(function(event){
        $(this).parent().css('height',$(this).parent().height()+'px');
        $(this).parent().animate({
            "overflow":"hidden",
            "border-top":"none",
            "border-bottom":"none",
            "padding": "0 15px",
            "margin":0,
            "height": "0px"
        }, 400);
    });
    

    这将要求 zepto 计算元素的当前高度,以便我们可以将其设置为 0。

    http://jsfiddle.net/HWaNj/5/

    【讨论】:

    • 这实际上过渡得非常好。
    • @ascom 我认为您的示例没有问题,但是如果您设置较短的持续时间,您可能会更喜欢它,因为它不是一个非常高的元素。例如尝试 200 毫秒:jsfiddle.net/HWaNj/3
    • 我更新了我的答案,新的没有跳转
    • 谢谢!现在它工作得很好。另外,我没有使用 jQuery - 我使用的是 Zepto(一个几乎与 jQuery 兼容的库)。
    猜你喜欢
    • 1970-01-01
    • 2021-02-04
    • 1970-01-01
    • 2012-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-08
    • 1970-01-01
    相关资源
    最近更新 更多