html - 创建一个在给定时间后出现的滑动 CSS 抽屉
问题描述
我想制作一个几秒钟后出现在页面底部的 CSS 滑动抽屉。我已经非常接近以下内容。我在开始时使用transform: translate(100%, 0);
in#supportroll
来隐藏 div。
问题是动画结束后,div消失了。如果我删除该初始转换,则 div 从一开始就出现在屏幕上。我尝试display
在关键帧中使用从 切换none
到block
,但这会使 div 根本不会出现或动画。什么是防止 div 在animation-delay
开始时间之前出现的好解决方案?
<html>
<body>
<div id="supportroll">
<div>Item 1</div>
<div>Item 2</div>
<div>Item 3</div>
<div>Item 4</div>
</div>
</body>
</html>
CSS:
#supportroll {
border: 2px solid #60047A;
position: fixed;
background-color: #012e2f;
color: white;
padding: 20px;
right: 0px;
bottom: 50px;
width: 100px;
transform: translate(100%, 0);
animation-delay: 1s;
animation-play-state: running;
animation-iteration-count: 1;
animation-duration: 5s;
animation-name: supportanimation;
}
@keyframes supportanimation {
from {
transform: translate(100%, 0);
}
to {
transform: translate(0%, 0);
}
}
解决方案
您可以像这样“破解”“时间段”:
#supportroll {
border: 2px solid #60047A;
position: fixed;
background-color: #012e2f;
color: white;
padding: 20px;
right: 0px;
bottom: 50px;
width: 100px;
transform: translate(0%, 0);
animation-delay: 0s; /* instead of 1 sec */
animation-play-state: running;
animation-iteration-count: 1;
animation-duration: 6s; /* instead of 5 sec */
animation-name: supportanimation;
opacity: 1; /* fade-in effect */
}
@keyframes supportanimation {
from {
transform: translate(200%, 0);
opacity:0;
}
to {
transform: translate(0%, 0);
opacity: 1;
}
}
<div id="supportroll">
<div>Item 1</div>
<div>Item 2</div>
<div>Item 3</div>
<div>Item 4</div>
</div>
推荐阅读
- c++ - 如何在程序执行时查看 Valgrind Massif 输出(或其他堆分析器)?
- python - 使用 Pandas 写入和读取 csv 文件,其中特定的列单元格值可以是 dicts 列表
- javascript - jQuery AJAX won't store data in a variable
- wxpython - 在 wxpython textctrl 字段中使用提示
- c# - .NET Core 基于角色的身份Cookie动态过期
- c# - 用零填充整数
- java - Android 类“GeofencingClient”不存在?
- javascript - 一种用 Webpack 循环 HTMLWebpackPlugin 的干净方法?
- node.js - 存储 node.js 站点设置的最佳方式是什么?
- python-3.x - 在 Python 中使用 bash 命令时权限被拒绝