jquery - 如何自动平滑地动画div高度

标签 jquery css animation html

我知道 jQuery animate 函数,我可以用它顺利地改变 div 高度,但问题是:

我有一个 div:

<div class="blah">Content with 3 lines</div>

然后我使用 jQuery 在上面的 div 中添加了更多行,div 高度是 auto 所以它会变长,但不会很顺利,无论如何它可以像使用 jQuery 一样顺利地变长动画函数?

我只是不想在任何附加、ajax 调用等上键入 animate({blah})。

是否可以在每次 div 高度变化时调用一个函数?并使用 animate 函数处理它?<​​/em>

我也读过关于转换的内容,所以我做了:

.blah{
    -webkit-transition: height 1s ease-in-out !important;
    -moz-transition: height 1s ease-in-out !important;
    -ms-transition: height 1s ease-in-out !important;
    -o-transition: height 1s ease-in-out !important;
    transition: height 1s ease-in-out !important;
}

但不工作

附加数据的 jQuery 方法:

$('blah').append('<p style="clear:both;">Another Line</p>')

提前致谢

最佳答案

Demo

jQuery

$("#blah")
    .hide()
    .html('<p>Another Line</p><p>Another Line</p><p>Another Line</p>')
    .slideDown('slow');

CSS

div {
    background:slategray;
    color:white;
    padding:20px;
}

关于jquery - 如何自动平滑地动画div高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23185861/

相关文章:

javascript - 获取原始图像进行裁剪,忽略宽度属性?

ios - 如何在按钮单击 ios Swift 上执行具有不同点的相同动画

Android TextView 数字动画

javascript - 如何在浏览器上无延迟地显示 "No Results"

javascript - 使用 spring mvc 和 apache pdf 框从 UI 下载的空的和损坏的 pdf 文件

javascript - 在部分 View MVC 中使用 jquery/js

css - 移动设备和桌面设备上的 Prestashop css 问题

php - 将 Git 与 Wordpress 结合使用

html - hr有一个尖头......如何摆脱这个?

javascript - 当我的动画完成时,transitionend 事件不会触发