0
点赞
收藏
分享

微信扫一扫

css--打字机效果

创建打字机效果动画。

  • 定义两个动画,​​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;
}
}


举报

相关推荐

0 条评论