CSS动画之间的延迟

时间:2018-07-05 18:55:23

标签: css css3 css-animations delay

我正在尝试在CSS中键入2行。我的问题是这两行是同时写入的。我尝试使用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 :(得分:0)

/*-----------------------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>

我想这就是您要寻找的。我的猜测是,您定义了两个具有相同名称的动画,因此您将其覆盖。另外,您还需要指定从.line-1.line-2的属性