Задержка между CSS-анимациями - PullRequest
0 голосов
/ 05 июля 2018

Я пытаюсь напечатать 2 строки в CSS. Моя проблема в том, что обе строки пишутся одновременно. Я пытался использовать свойство animation-delay, но оно не работает должным образом. Как я могу набрать первую строку, а затем набрать вторую строку?

/*-----------------------LINE 1-----------------------*/

.line-1{
font-family: monospace;
position: relative;
top: 30%;
left: 15%;
width: 24em;
margin: 0 auto;
font-size: 250%;
text-align: left;
white-space: nowrap;
overflow: hidden;
transform: translateY(-50%);
}

/* Animation */
.anim-typewriter{
  animation: typewriter 4s steps(44) 1s 1 normal both,
           blinkTextCursor 500ms steps(44) infinite normal;
}
@keyframes typewriter{
  from{width: 0;}
  to{width: 9.5em;}
}
@keyframes blinkTextCursor{
  from{border-right-color: rgba(255,255,255,.75);}
  to{border-right-color: transparent;}
}

/*-----------------------LINE 2-----------------------*/

/* Animation */
.anim-typewriter2{
  animation: typewriter 4s steps(44) 1s 1 normal both,
         blinkTextCursor 500ms steps(44) infinite normal;
         animation-delay: 4s;
 }
 @keyframes typewriter{
   from{width: 0;}
   to{width: 15em;}
 }
 @keyframes blinkTextCursor{
   from{border-right-color: rgba(255,255,255,.75);}
   to{border-right-color: transparent;}
 }
<p class="line-1 anim-typewriter">Hi, I'm Mohanad,</p>
<p class="line-2 anim-typewriter2">I do cool computer stuff.</p>

1 Ответ

0 голосов
/ 05 июля 2018

/*-----------------------LINE 1-----------------------*/

.line-1, .line-2 {
  font-family: monospace;
  position: relative;
  top: 30%;
  left: 15%;
  width: 24em;
  margin: 0 auto;
  font-size: 250%;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  transform: translateY(-50%);
}

/* Animation */
.anim-typewriter {
  animation: typewriter1 4s steps(44) 1s 1 normal both,
           blinkTextCursor1 500ms steps(44) infinite normal;
}
@keyframes typewriter1 {
  from {
    width: 0;
  }
  
  to{
    width: 9.5em;
  }
}
@keyframes blinkTextCursor1 {
  from {
    border-right-color: rgba(255,255,255,.75);
  }
  
  to {
    border-right-color: transparent;
  }
}

/*-----------------------LINE 2-----------------------*/

/* Animation */
.anim-typewriter2{
  animation: typewriter2 4s steps(44) 1s 1 normal both,
         blinkTextCursor2 500ms steps(44) infinite normal;
         animation-delay: 5s;
 }
 @keyframes typewriter2 {
   from {
    width: 0;
  }
  
  to {
    width: 15em;
  }
 }
 @keyframes blinkTextCursor2 {
   from {
    border-right-color: rgba(255,255,255,.75);
  }
   
  to {
    border-right-color: transparent;
  }
 }
<p class="line-1 anim-typewriter">Hi, I'm Mohanad,</p>
<p class="line-2 anim-typewriter2">I do cool computer stuff.</p>

Я думаю, это то, что вы ищете. Я предполагаю, что вы определили 2 анимации с одинаковыми именами и поэтому перезаписали их. Также вам нужно было указать свойства от .line-1 до .line-2

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...