首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >动画不运行

动画不运行
EN

Stack Overflow用户
提问于 2017-08-20 12:29:22
回答 1查看 31关注 0票数 0

我正在尝试使用CSS动画制作一个加载屏幕。屏幕是四个不同的条收缩和增长。我想把它们排列成正方形。我使用绝对定位来定位它们,但我想知道是否有更好的方法。我设法做了3条显示和浮动,但没有设法做最后一个。

现在,动画根本没有运行。有人能帮我吗?

代码:https://codepen.io/ngmh/pen/gxewJK

HTML:

代码语言:javascript
复制
<div id="top"></div>
<div id="right"></div>
<div id="bottom"></div>
<div id="left"></div>

CSS:

代码语言:javascript
复制
#top{
  background-color: red;
  width: 100px;
  height: 25px;
  border-radius: 12.5px;
  position: absolute;
  left: 37.5px;
  animation-name: loading-1;
  animation-duration: 4s;
  animation-iteration-count: infinite;
}
#bottom{
  background-color: yellow;
  width: 100px;
  height: 25px;
  border-radius: 12.5px;
  position: absolute;
  top: 112.5px;
  animation-name: loading-1;
  animation-duration: 4s;
  animation-iteration-count: infinite;
}
#left{
  background-color: blue;
  width: 25px;
  height: 100px;
  border-radius: 12.5px;
  animation-name: loading-2;
  animation-duration: 4s;
  animation-iteration-count: infinite;
}
#right{
  background-color: green;
  width: 25px;
  height: 100px;
  border-radius: 12.5px;
  position: absolute;
  left: 112.5px;
  top: 37.5px;
  animation-name: loading-2;
  animation-duration: 4s;
  animation-iteration-count: infinite;
}
@keyframes loading-1{
  0%:{width: 100px;}
  50%:{width: 10px;}
  100%:{width: 100px;}
}
@keyframes loading-2{
  0%:{height: 100px;}
  50%:{height: 10px;}
  100%:{height: 100px;}
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-08-20 12:32:52

在您的:规则中签名百分比%之后,不应该有任何冒号%

代码语言:javascript
复制
#top{
  background-color: red;
  width: 100px;
  height: 25px;
  border-radius: 12.5px;
  position: absolute;
  left: 37.5px;
  animation-name: loading-1;
  animation-duration: 4s;
  animation-iteration-count: infinite;
}
#bottom{
  background-color: yellow;
  width: 100px;
  height: 25px;
  border-radius: 12.5px;
  position: absolute;
  top: 112.5px;
  animation-name: loading-1;
  animation-duration: 4s;
  animation-iteration-count: infinite;
}
#left{
  background-color: blue;
  width: 25px;
  height: 100px;
  border-radius: 12.5px;
  animation-name: loading-2;
  animation-duration: 4s;
  animation-iteration-count: infinite;
}
#right{
  background-color: green;
  width: 25px;
  height: 100px;
  border-radius: 12.5px;
  position: absolute;
  left: 112.5px;
  top: 37.5px;
  animation-name: loading-2;
  animation-duration: 4s;
  animation-iteration-count: infinite;
}
@keyframes loading-1{
  0% {width: 100px;}
  50% {width: 10px;}
  100% {width: 100px;}
}
@keyframes loading-2{
  0% {height: 100px;}
  50% {height: 10px;}
  100% {height: 100px;}
}
代码语言:javascript
复制
<div id="top"></div>
<div id="right"></div>
<div id="bottom"></div>
<div id="left"></div>

使用伪元素将使标记更小,并且可能更易于维护。

outer不使用绝对定位,它将更好地与其他内容一起流动。

代码语言:javascript
复制
.outer {
  position: relative;
}
.outer div,
.outer::before,
.outer::after,
.outer div::before,
.outer div::after {
  content: '';
  position: absolute;
  border-radius: 12.5px;
  animation-duration: 4s;
  animation-iteration-count: infinite;
}
.outer::before {
  background-color: red;
  width: 100px;
  height: 25px;
  left: 37.5px;
  animation-name: loading-1;
}
.outer::after{
  background-color: yellow;
  width: 100px;
  height: 25px;
  top: 112.5px;
  animation-name: loading-1;
}
.outer div::before{
  background-color: blue;
  width: 25px;
  height: 100px;
  animation-name: loading-2;
}
.outer div::after{
  background-color: green;
  width: 25px;
  height: 100px;
  left: 112.5px;
  top: 37.5px;
  animation-name: loading-2;
}
@keyframes loading-1{
  0% {width: 100px;}
  50% {width: 10px;}
  100% {width: 100px;}
}
@keyframes loading-2{
  0% {height: 100px;}
  50% {height: 10px;}
  100% {height: 100px;}
}
代码语言:javascript
复制
<div class="outer"><div></div></div>

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45782138

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档