css - CSS动画方向问题
问题描述
我们正在尝试为 div 设置动画,如下所示:
1- 从 0 拉伸到 100%(从左到右)
2- 然后从 100% 缩小到 0(也是从左到右)
3-然后重复。
我们有以下 div:
div {
position: absolute;
height: 2px;
background: #c60000;
left: 0;
top: 0;
color: #789;
width: 0;
animation-duration: 5s;
animation-name: progress;
animation-iteration-count: infinite;
}
@keyframes progress {
50% {
// transform-origin: right top;
width: 100%;
}
}
<div></div>
但无论我们使用变换原点和浮点数、定位等做什么,第二部分都会从右向左收缩。即左侧始终是锚点,而我们希望在发生收缩时右侧成为锚点。
将不胜感激任何帮助。
解决方案
div {
position: absolute;
height: 2px;
background: #c60000;
top: 0;
color: #789;
animation-duration: 5s;
animation-name: progress;
animation-iteration-count: infinite;
animation-timing-function: linear;
}
@keyframes progress {
0% {
left: 0;
width: 0;
}
50% {
right: 0;
width: 100%;
}
100% {
right: 0;
width: 0;
}
}
<div></div>
推荐阅读
- javascript - 如何将 mp3 文件从 Java 后端发送到前端并在 Vue.js 前端播放文件
- php - 在结帐重定向到错误的 URL 之前检查并重定向以登录
- python - 如何使用 Tkinter 使用下拉菜单打开文件夹中的文件
- ios - 安装新的 iOS 应用后接收相同的 FCM 令牌
- amazon-web-services - Gitlab runner 使用 IAM ROLE 在 Spot 实例中自动扩展
- javascript - 基于 XHR 的 ajax 无法上传文件
- sas - 将行转换为数据集中的变量
- asp.net-mvc - 如何在对 ASP.NET 核心服务器的 POST 请求正文中使用字符串化枚举?
- java - 为本地环境禁用 @SqsListener
- sql - Postgres & Rust R2D2:如何在没有转义双引号的情况下将 array_to_json 作为文本/字符串?