Issue
I have this HTML
<div class=typewriter>
<h1>Lorem Ipsum</h1>
</div>
and this CSS
.typewriter {
display: inline-block;
}
.typewriter h1 {
overflow: hidden;
border-right: .15em solid black;
white-space: nowrap;
margin: 0 auto;
letter-spacing: .15em;
animation:
typing 3.5s steps(30, end),
blink .75s step-end 0s infinite;
}
@keyframes typing {
from {
width: 0;
}
to {
width: 100%;
}
}
@keyframes blink {
0%,
100% {
border-color: black;
}
50% {
border-color: transparent;
}
}
The animation is almost perfect, but I need the cursor to disappear after 3 seconds at the end of animation.
How can I do it? Also, there's anything I could improve?
I look at other questions like this one, but it didn't solve the problem.
Solution
Simply add another keyframe.
.typewriter {
display: inline-block;
}
.typewriter h1 {
overflow: hidden;
border-right: .15em solid black;
white-space: nowrap;
margin: 0 auto;
letter-spacing: .15em;
animation:
typing 3.5s steps(30, end),
blink .75s step-end 0s infinite,
end 3s 3.5s forwards;
}
@keyframes typing {
from {
width: 0;
}
to {
width: 100%;
}
}
@keyframes blink {
0%,
100% {
border-color: black;
}
50% {
border-color: transparent;
}
}
@keyframes end {
to {
border-right: 0 solid transparent;
}
}
<div class="typewriter">
<h1>Lorem Ipsum</h1>
</div>
In this example, I have added end
. After 3 seconds (feel free to change it), the color of border-right
should be transparent.
Answered By - Reza Saadati
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.