【发布时间】:2020-10-03 04:23:51
【问题描述】:
在我模拟打字机(仅 html/css)的动画中,我想再添加 4 个变量文字,但我不能,因为我不明白如何使用关键帧。我试过了,但他同时写了几个字。
第二个问题是我不能准确地将“Hi, i'm a”放在中间,并在它必须写变量字时让它向左移动。 (例如:https://codepen.io/sheikh_ishaan/pen/LYEOqjd)
.box_type{
margin-left: auto;
margin-right: auto;
width: 30em;
}
h1.type {
font-size: 30px;
display:flex;
align-items: baseline;
}
.text_1 {
animation: text1;
}
.text_2 {
animation: text2;
}
.text_1, .text_2 {
overflow: hidden;
white-space: nowrap;
display: inline-block;
position: relative;
animation-duration: 20s;
animation-timing-function: steps(25, end);
animation-iteration-count: infinite;
}
.text_1::after, .text_2::after {
content: "|";
position: absolute;
right: 0;
animation: caret infinite;
animation-duration: 1s;
animation-timing-function: steps(5, end);
}
@keyframes text2 {
0%, 50%, 100% {
width: 0;
}
60%, 90% {
width: 6.50em;
}
}
@keyframes text1 {
0%, 50%, 100% {
width: 0;
}
10%, 40% {
width: 8em;
}
}
@keyframes caret {
0%, 100% {
opacity: 0;
}
50% {
opacity: 1;
}
}
<div class="box_type">
<h1 class="type">Hi, i'm a <span class="text_1"> Graphic Designer</span><span class="text_2"> Photographer</span></h1>
</div>
【问题讨论】:
-
添加到
h1.typejustify-content: center; -
@GrzegorzT。哦,我是愚蠢的!非常感谢
-
@GrzegorzT。你知道如何添加更多可变词吗?
-
请参考我的第二个回答
标签: html css animation css-animations keyframe