css - 你如何堆叠CSS动画
问题描述
我有一个要制作动画的 CSS 元素。盒子从高度 30px 开始。单击时,我希望框首先缩小到高度 0px,然后动画到 60px
document.getElementById("box1").style = "transition: height 0s; transition-delay: 0s; height:0px";
document.getElementById("box1").style = "transition: height .50s; transition-delay: .50s; height:60px";
我尝试了上述方法,但第二行覆盖了第一行。
解决方案
这是一个应该有帮助的例子:https ://jsfiddle.net/qshruafp/
document.getElementById("box1").addEventListener('click', ManageBoxClick);
function ManageBoxClick() {
console.log('Entered ManageBoxClick');
document.getElementById("box1").animate([
// keyframes
{ height: '30px' },
{ height: '0px' },
{ height: '60px' }
], {
// timing options
duration: 1000
});
}
#box1 {
position relative;
display: block;
background-color: blue;
width: 30px;
height: 30px;
cursor: pointer;
pointer-events: all;
}
<div id="box1"></div>
推荐阅读
- .net - .NET Framework 有发布任务吗?(不是 .NET 核心)
- python - 背景移动速度逐渐增加
- react-native - React Native:-[未处理的承诺拒绝:TypeError:null 不是对象(评估'_InCallManager.checkCameraPermission')]
- laravel - 是否可以在 Web 服务器上使用 Artisan 命令?
- ios - 即使用户强制退出应用,如何确保用户继续收到推送通知?
- excel - 如何设置价值没有 .value 选项的元素?
- flutter - 如何在颤动中显示表情符号
- javascript - 即使使用开放的安全规则,Firebase 读取权限也会被拒绝
- linkki - 我可以在 linkki 中嵌套演示模型对象 (PMO) 吗?
- google-cloud-platform - 来自文件夹级日志的 GCP Logging 基于日志的指标?