创建打字机效果动画。
- 定义两个动画,
typing以动画角色和blink动画插入符号。 - 使用
:after伪元素将插入符号添加到容器元素。 - 使用 JavaScript 设置内部元素的文本并设置
--characters包含字符数的变量。此变量用于为文本设置动画。 - 根据需要使用
white-space: nowrap和overflow: hidden使内容不可见。 
 
 
<div class="typewriter-effect">
  <div class="text" id="typewriter-text"></div>
</div> 
.typewriter-effect {
  display: flex;
  justify-content: center;
  font-family: monospace;
}
.typewriter-effect > .text {
  max-width: 0;
  animation: typing 3s steps(var(--characters)) infinite;
  white-space: nowrap;
  overflow: hidden;
}
.typewriter-effect:after {
  content: " |";
  animation: blink 1s infinite;
  animation-timing-function: step-end;
}
@keyframes typing {
  75%,
  100% {
    max-width: calc(var(--characters) * 1ch);
  }
}
@keyframes blink {
  0%,
  75%,
  100% {
    opacity: 1;
  }
  25% {
    opacity: 0;
  }
}                










