【发布时间】:2020-08-01 14:20:59
【问题描述】:
我正在尝试创建一个带有模拟终端的网站,该终端具有被键入的行的外观,一个接一个。我发现了一个一次显示一个字符的 CSS 动画,但我遇到了延迟每一行动画的问题,这样它们就不会一次全部出现。
这是我的代码:
//attempted javascript loop
// var code_lines =document.getElementsByClassName("line");
// for (i=0; i<=5; i++){
// code_lines:nth-child(i).style.animation = "typing 2.5s steps(30, end)";
// }
//attemped jquery loop
//$('#terminal_text').children('line').each(function () {
// for (i=0; i<=5; i++){
// i.style.animation = "typing 2.5s steps(30, end)";
//}
//});
.terminal {
width: 500px;
height: 500px;
background-color: black;
color: white;
padding: 20px;
}
.line {
white-space: nowrap;
overflow: hidden;
transform: translateY(-50%);
animation: typing 2.5s steps(30, end);
}
/* The typing effect */
@keyframes typing {
from { width: 0 }
to { width: 100% }
}
<div class="terminal">
<div id="terminal_text">
<p class="line"> Last login: </p>
<p class="line">megan-byers:~ designelixir$ git clone https://github.com/coloradical/Rae_Portfolio.git </p>
<p class="line">Cloning into 'Rae_Portfolio"...</p>
<p class="line">remote: Loading website illustrations: 172 objects, done.</p>
<p class="line">remote: Counting objects: 100% (172/172) done.</p>
</div>
</div>
我会调整时间,但现在我只想让动画一个接一个地开始。我很难找到如何使用班级儿童应用动画的清晰示例。任何指导将不胜感激!
【问题讨论】:
-
相关:stackoverflow.com/a/60939523/8620333 .. 或许会给你不一样的想法
标签: javascript jquery html css