我正在学习CSS动画,并且我认为我从概念上了解了它的工作原理。
我决定创建一个加载微调器:一个div,其宽度/高度为0,但其边界经过调整以创建“钻石”外观:
然后的想法是,此微调框的动画将有5个“状态”:
我认为上述逻辑实现很简单:
然后确保将动画设置为无穷大,就这样,这就是实现,并且它肯定不能按我上面期望的那样工作。
.spinner {
/* initial state 0 */:
position: absolute;
left: 20px;
top: 20px;
width: 0px;
height: 0px;
border-left: 100px solid darkgrey;
border-top: 100px solid lightgrey;
border-right: 100px solid grey;
border-bottom: 100px solid black;
background-color: dimgrey;
animation: spinning 3s infinite;
}
@keyframes spinning {
0%, 100% {
/* initial state 0 */
border-left: 100px solid darkgrey;
border-top: 100px solid lightgrey;
border-right: 100px solid grey;
border-bottom: 100px solid black;
}
20% {
/* state 1 */
border-left: 100px solid darkgrey;
border-top: 100px solid transparent;
border-right: 100px solid transparent;
border-bottom: 100px solid transparent;
}
40% {
/* state 2 */
border-left: 100px solid transparent;
border-top: 100px solid lightgrey;
border-right: 100px solid transparent;
border-bottom: 100px solid transparent;
}
60% {
/* state 3 */
border-left: 100px solid transparent;
border-top: 100px solid transparent;
border-right: 100px solid grey;
border-bottom: 100px solid transparent;
}
80% {
/* state 4 */
border-left: 100px solid transparent;
border-top: 100px solid transparent;
border-right: 100px solid transparent;
border-bottom: 100px solid black;
}
}
<div class="spinner"></div>
我在这里想念什么?我想了解以下逻辑CSS动画?我阅读了一些有关CSS技巧的文章,但这些是更多有用的示例,我想掌握背后的概念; /有什么建议吗?
更新:似乎我留下了一些逗号;(修正了例子
答案 0 :(得分:3)
您的keyframes
定义中的逗号和冒号打破了它。删除它们,使它看起来像这样:
@keyframes spinning {
0%, 100% {
/* initial state 0 */
border-left: 100px solid darkgrey;
border-top: 100px solid lightgrey;
border-right: 100px solid grey;
border-bottom: 100px solid black;
}
20% {
/* state 1 */
border-left: 100px solid darkgrey;
border-top: 100px solid transparent;
border-right: 100px solid transparent;
border-bottom: 100px solid transparent;
}
40% {
/* state 2 */
border-left: 100px solid transparent;
border-top: 100px solid lightgrey;
border-right: 100px solid transparent;
border-bottom: 100px solid transparent;
}
60% {
/* state 3 */
border-left: 100px solid transparent;
border-top: 100px solid transparent;
border-right: 100px solid grey;
border-bottom: 100px solid transparent;
}
80% {
/* state 4 */
border-left: 100px solid transparent;
border-top: 100px solid transparent;
border-right: 100px solid transparent;
border-bottom: 100px solid black;
}
}