Ключевые кадры CSS для повторения эффекта мерцания (Wi-Fi) - PullRequest
0 голосов
/ 18 декабря 2018

, поэтому я пытаюсь создать эффект Wi-Fi мигания для проекта.Сначала должен быть виден круг, затем тот, что выше, и так далее.После того, как все символы видны, нужно подождать 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>

Ответы [ 2 ]

0 голосов
/ 18 декабря 2018

Я бы сделал это с одним элементом, чтобы упростить управление анимацией и уменьшить количество кода:

.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>
0 голосов
/ 18 декабря 2018

Создание нескольких анимаций, каждая из которых запускает анимацию с разным процентом. Затем можно пропустить задержку анимации.

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>
...