html - 使css动画无限运行
问题描述
有这个 html/css 片段:
.triangle-four {
width: 0;
height: 0;
border-left: 150px solid transparent;
border-right: 150px solid transparent;
border-bottom: 250px solid rgb(20, 97, 27);
margin-top: -120px;
animation-name: example;
animation-duration: 4s;
}
@keyframes example {
0% {
background-color: red;
}
25% {
background-color: yellow;
}
50% {
background-color: blue;
}
100% {
background-color: green;
}
<div class="triangle-four"></div>
我想让它无限运行并尝试这样做:
animation-duration: 4s infinite;
它不起作用,即使认为这是w3schools上推荐的操作,动画也不再起作用。
有任何想法吗?
解决方案
我删除animation-name: example; animation-duration: 4s;
并添加animation: example 5s infinite;
它,它将解决您的问题。
另一个解决方案只是添加它而不删除任何东西:
animation-iteration-count: infinite;
.triangle-four {
width: 0;
height: 0;
border-left: 150px solid transparent;
border-right: 150px solid transparent;
border-bottom: 250px solid rgb(20, 97, 27);
margin-top: -120px;
animation: example 5s infinite;
}
@keyframes example {
0% {
background-color: red;
}
25% {
background-color: yellow;
}
50% {
background-color: blue;
}
100% {
background-color: green;
}
}
<div class="triangle-four"></div>
推荐阅读
- javascript - 如何仅对没有 parentId 的项目和具有 parentId 的项目保留第一项的项目按 id 分组?
- android - 需要根据屏幕设置 PopupWindow 位置
- java - Firebase 实时数据库:有没有办法从不同的节点获取价值?
- ruby-on-rails - 具有嵌套属性的未定义方法
- reactjs - 每次测试的笑话模拟值
- javascript - 使用 jquery 提交表单不起作用
- angular - 过滤特定数据并出现错误无法绑定到“ngModel”
- javascript - 在php中获取相同大小的图像
- python - 在熊猫数据框中保持大于阈值的值的计数
- android - 使用 customview 自定义 AppbarLayout