我正在尝试创建一种打字效果,将文本写出来,然后在句子末尾,光标闪烁2秒,然后开始下一句话(second h1),然后写下一句话。
body {
background: #333;
padding-top: 5em;
display: flex;
justify-content: center;
}
.typewriter h1 {
color: #fff;
font-family: monospace;
overflow: hidden;
border-right: .15em solid orange;
white-space: nowrap;
margin: 0 auto;
letter-spacing: .15em;
animation: typing 3.5s steps(30, end), blink-caret .5s;
}
@keyframes typing {
from {
width: 0
}
to {
width: 100%
}
}
@keyframes blink-caret {
from,
to {
border-color: transparent
}
50% {
border-color: orange
}
}<div class="typewriter">
<h1>First Sentence Here</h1>
<h1>Second Sentence Here</h1>
</div>
发布于 2019-11-02 05:48:05
您可以使用CSS变量添加animation-delay。对于每个h1元素(接受第一个元素-它使用默认值),设置--delay变量。这将为每个动画添加相关的延迟。
您还应该将animation-fill-mode更改为both,以便项目将保留其开始和结束状态。
body {
background: #333;
padding-top: 5em;
display: flex;
justify-content: center;
}
.typewriter h1 {
color: #fff;
font-family: monospace;
overflow: hidden;
border-right: .15em solid orange;
white-space: nowrap;
margin: 0 auto;
letter-spacing: .15em;
animation: typing 3.5s steps(30, end) both, blink-caret .5s both;
animation-delay: calc(var(--delay, 0) * 1s), calc(var(--delay, 0) * 1s + 3.5s);
}
@keyframes typing {
from {
width: 0
}
to {
width: 100%
}
}
@keyframes blink-caret {
from,
to {
border-color: transparent
}
50% {
border-color: orange
}
}<div class="typewriter">
<h1>First Sentence Here</h1>
<h1 style="--delay: 4">Second Sentence Here</h1>
</div>
https://stackoverflow.com/questions/58666212
复制相似问题