CSS 重复闪烁效果的关键帧 (wifi)

CSS Keyframes for repeating blink effect (wifi)

所以我正在尝试为项目创建 Wifi 闪烁效果。首先圆圈应该是可见的,然后是上面的圆圈,依此类推。在所有符号都可见后,它应该等待 2 秒,然后重新开始。你可以在这里看到我的当前状态:

http://jsfiddle.net/6jhgfdv0/

我在css中使用的是

animation: blink 3s infinite;
animation-delay: 1s;

@keyframes blink {
    0% {opacity: 0}
    49%{opacity: 0}
  50%{opacity: 1}
}

我想只改变延迟和其他值我可以让它看起来像那样,但它不起作用。我做错了什么?

body {
  margin: 0;
  padding: 0;
}
  
  #body {
    margin: 200px auto 0px;
    width: 280px;
    height: 84px;
    background-color: #c9e3ed;
    border-radius: 30px 30px 10px 10px / 20px 20px 10px 10px;
    position: relative;
 }
      
 #wifi .signal {
    border-right: 12px solid #ee7230;
    border-bottom: 12px solid #ee7230;
    border-top: 1px solid #fff;
    border-left: 1px solid #fff;
    transform: rotate(-135deg);
    position: absolute;
}
  
 #wifi .signal:first-child {
 left: 50%;
 top: -160px;
 margin-left: -56px;  
 width: 100px;
 height: 100px;
 border-radius: 0 0 100px 0;
 animation: blink 3s infinite;
 animation-delay: 1s;
}

 #wifi .signal:nth-child(2) {
 left: 50%;
 top: -130px;
 margin-left: -43px;  
 width: 74px;
 height: 74px;
 border-radius: 0 0 74px 0;
 animation: blink 3s infinite;
 animation-delay: 2s;
 }   
  
 #wifi .signal:last-child {
 left: 50%;
 top: -100px;
 margin-left: -30px;  
 width: 48px;
 height: 48px;
 border-radius: 0 0 48px 0;
 animation: blink 3s infinite;
 animation-delay: 3s;
}

 #wifi .signal:last-child:after {
 content: '';
 position: absolute;
 right: 35%;
 bottom: 35%;
 height: 30px;
 width: 30px;
 background-color: #ee7230;
 border-radius: 50%;
 margin-left: -25px;
 animation: blink 3s infinite;
 animation-delay: 4s;
}


@keyframes blink {
 0% {opacity: 0}
 49%{opacity: 0}
  50%{opacity: 1}
}
<div id="router">
  <div id="body">
    <div id="wifi">
      <div class="signal"></div>
      <div class="signal"></div>
      <div class="signal"></div>
    </div>
  </div>
</div>

创建多个动画,每个动画将以不同的百分比启动动画,然后您可以跳过动画延迟。

body {
  margin: 0;
  padding: 0;
}

#body {
  margin: 200px auto 0px;
  width: 280px;
  height: 84px;
  background-color: #c9e3ed;
  border-radius: 30px 30px 10px 10px / 20px 20px 10px 10px;
  position: relative;
}

#wifi .signal {
  border-right: 12px solid #ee7230;
  border-bottom: 12px solid #ee7230;
  border-top: 1px solid #fff;
  border-left: 1px solid #fff;
  transform: rotate(-135deg);
  position: absolute;
}

#wifi .signal:first-child {
  left: 50%;
  top: -160px;
  margin-left: -56px;
  width: 100px;
  height: 100px;
  border-radius: 0 0 100px 0;
  animation: blink4 4s infinite;
}

#wifi .signal:nth-child(2) {
  left: 50%;
  top: -130px;
  margin-left: -43px;
  width: 74px;
  height: 74px;
  border-radius: 0 0 74px 0;
  animation: blink3 4s infinite;
}

#wifi .signal:last-child {
  left: 50%;
  top: -100px;
  margin-left: -30px;
  width: 48px;
  height: 48px;
  border-radius: 0 0 48px 0;
  animation: blink2 4s infinite;
}

#wifi .signal:last-child:after {
  content: '';
  position: absolute;
  right: 35%;
  bottom: 35%;
  height: 30px;
  width: 30px;
  background-color: #ee7230;
  border-radius: 50%;
  margin-left: -25px;
  animation: blink1 4s infinite;
}

@keyframes blink1 {
  0% {
    opacity: 0
  }
  19% {
    opacity: 0
  }
  20% {
    opacity: 1
  }
}

@keyframes blink2 {
  0% {
    opacity: 0
  }
  39% {
    opacity: 0
  }
  40% {
    opacity: 1
  }
}

@keyframes blink3 {
  0% {
    opacity: 0
  }
  59% {
    opacity: 0
  }
  60% {
    opacity: 1
  }
}

@keyframes blink4 {
  0% {
    opacity: 0
  }
  79% {
    opacity: 0
  }
  80% {
    opacity: 1
  }
}
<div id="router">
  <div id="body">
    <div id="wifi">
      <div class="signal"></div>
      <div class="signal"></div>
      <div class="signal"></div>
    </div>
  </div>
</div>

我会用一个元素来做到这一点,以便通过动画更轻松地控制并减少代码:

.wifi {
  margin:20px;
  width:290px;
  height:290px;
  display:inline-block;
  background:
    /*the center*/
    radial-gradient(circle at center, orange 20px,transparent 21px),
    /*some white to hide part of the circles*/
    linear-gradient( 45deg, #fff 50%,transparent 0),
    linear-gradient(-45deg, #fff 50%,transparent 0),
    /*--*/
    /*1*/
    radial-gradient(circle at center,
      transparent 40px,orange 41px,
      orange 61px,transparent 62px),
    /*2*/
    radial-gradient(circle at center,
      transparent 80px,orange 81px,
      orange 101px,transparent 102px),
    /*3*/
    radial-gradient(circle at center,
      transparent 120px,orange 121px,
      orange 141px,transparent 142px);
  animation:change 5s linear infinite;
}

@keyframes change {
  0%,20% {
    background-size: 0,auto, auto, 0, 0,0;
  }
  20%,40% {
    background-size: auto,auto, auto, 0, 0,0;
  }
  40%,60% {
    background-size: auto,auto, auto, auto, 0,0;
  }
  60%,80% {
    background-size: auto,auto, auto, auto, auto,0;
  }
  80%,100% {
    background-size: auto,auto, auto, auto, auto,auto;
  }
}
<div class="wifi"></div>

还有一些 CSS 变量可以更容易地调整值:

.wifi {
  --d:20px; /*the distance between signals*/
  --l:20px; /*the lenght of the signals*/
  --s:calc(var(--l) + var(--d));
  width:calc(7*var(--s) + var(--l));
  height:calc(7*var(--s) + var(--l));
  display:inline-block;
  background:
    /*the center*/
    radial-gradient(circle at center, 
    orange var(--l),transparent calc(var(--l) + 1px)),
    /*some white to hide part of the circles*/
    linear-gradient( 45deg, #fff 50%,transparent 0),
    linear-gradient(-45deg, #fff 50%,transparent 0),
    /*--*/
    /*1*/
    radial-gradient(circle at center,
      transparent calc(1*var(--s)),
      orange      calc(1*var(--s) + 1px),
      orange      calc(1*var(--s) + var(--l)),
      transparent calc(1*var(--s) + var(--l) + 1px)),
    /*2*/
    radial-gradient(circle at center,
      transparent calc(2*var(--s)),
      orange      calc(2*var(--s) + 1px),
      orange      calc(2*var(--s) + var(--l)),
      transparent calc(2*var(--s) + var(--l) + 1px)),
    /*3*/
    radial-gradient(circle at center,
      transparent calc(3*var(--s)),
      orange      calc(3*var(--s) + 1px),
      orange      calc(3*var(--s) + var(--l)),
      transparent calc(3*var(--s) + var(--l) + 1px));
  animation:change 5s linear infinite;
}

@keyframes change {
  0%,20% {
    background-size: 0,auto, auto, 0, 0,0;
  }
  20%,40% {
    background-size: auto,auto, auto, 0, 0,0;
  }
  40%,60% {
    background-size: auto,auto, auto, auto, 0,0;
  }
  60%,80% {
    background-size: auto,auto, auto, auto, auto,0;
  }
  80%,100% {
    background-size: auto,auto, auto, auto, auto,auto;
  }
}
<div class="wifi"></div>

<div class="wifi" style="--l:10px;"></div>

<div class="wifi" style="--l:10px;--d:5px"></div>