css - 有没有什么办法可以通过变换属性实现不断增长的 div 动画?

标签 css

我使用以下样式开发了一个 div 在其中增长的动画:

.animation-start {
   overflow: hidden;
   height: 0;
}

.animation-end {
   height: 100px;
}

但这种方法的问题在于它在移动设备上呈现不流畅。目前,唯一在手机上流畅呈现的动画是使用 transform 属性的动画。有什么方法可以仅使用变换属性(不使用高度属性)来实现不断增长的 div 动画?

最佳答案

是的,您可以只向元素添加持续时间:

$(document).click(function(){
    $('div').toggleClass('animation-end');
});
div {
    background: #ffc;
    transition-duration: 300ms;
}
.animation-start {
    overflow: hidden;
    height: 0;
}
.animation-end {
    height: 100px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="animation-start">asdf</div>
click anywhere

关于css - 有没有什么办法可以通过变换属性实现不断增长的 div 动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26604366/

相关文章:

jquery - 让文本区域充当输入

html - 将鼠标悬停在其他 div 上时移动 div

html - 垂直居中菜单偏移

jquery - 保持选项卡处于事件状态,默认打开选项卡

css - Sass 不编译

html - 我们是否仍应使用 EM 来实现可访问性?

html - HTML 中的链接图像(包装链接和内部链接)不会是 'link'

html - 使位置元素相互粘附

javascript - 更改所有 <hr> html 元素的属性

jquery - IE7 在滚动之前不会加载可滚动的 div 中的内容