javascript - 使用 Zepto jumpy 的 Bootstrap 警告框高度动画

标签 javascript twitter-bootstrap animation zepto

我正在尝试在用户单击关闭按钮时使 Bootstrap 警告框平滑地隐藏。然而,Zepto 使警告框以一种非常奇怪的方式运行: gif animation of me clicking the button, yay licecap!

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

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

这是一个 fiddle :http://jsfiddle.net/ascom/HWaNj/

如何使警告框动画流畅?

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

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

最佳答案

好像是没有预定义的高度和溢出有关。此外,边距和填充的使用也会扭曲动画。看看这个工作示例。

$(".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/

关于javascript - 使用 Zepto jumpy 的 Bootstrap 警告框高度动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22649046/

相关文章:

Angular 4 "export ' 在 '@angular/animations' 中找不到“AnimationEvent”

javascript - Three.js 中几何体的缩放动画

javascript - angular js中的包含属性

javascript - 从 ajax API 响应加载数据时,Bootstrap dataTable 搜索和分页不起作用

javascript - 居中输入字段 - 问题

html - 打印一个 Bootstrap 网站

html - 将 th 文本与 margin auto 居中对齐不适用

java - 在组件下方绘制图形

php - 用Jquery-Ajax不充值菜单刷新页面

javascript - 计时器自动启动,而不是在 javascript 中按下按钮