【发布时间】:2017-11-26 21:38:53
【问题描述】:
所以我已经实现了使用 CSS 动画输入我的名字。这样做的目的是在完成输入后使光标停留在句子的末尾,从而产生打字效果。
但是,就我而言,光标会上升到屏幕的末尾并在那里等待,我不希望这样。
我已经参考了这个tutorial 来实现打字效果。正如您在教程中看到的那样,光标在句子完成后停止,并且不会运行到屏幕末尾。
我的 CSS sn-p 也是一样的:
.titles {
position: absolute;
top: 15%;
left: 0;
right: 0;
}
h1 {
font-size: 4.5em;
color: white;
font-family: 'Droid Sans', serif;
letter-spacing: 2px;
pointer-events: none;
font-weight: 500;
border: 0px;
margin: 0px;
text-align: center;
/*color: #7a9fd0;*/
color: #595959;
}
.typewriter h1 {
overflow: hidden; /* Ensures the content is not revealed until the animation */
border-right: .15em solid orange; /* The typwriter cursor */
white-space: nowrap; /* Keeps the content on a single line */
margin: 0 auto; /* Gives that scrolling effect as the typing happens */
letter-spacing: 2px; /* Adjust as needed */
animation:
typing 4s steps(30, end),
blink-caret .75s /*step-end*/steps(50, end) infinite;
}
/* The typing effect */
@-webkit-keyframes typing {
from { width: 0 }
to { width: 100% }
}
/* The typewriter cursor effect */
@-webkit-keyframes blink-caret {
from, to { border-color: transparent }
50% { border-color: orange; }
}
对应index.html sn-p:
<div class="typewriter">
<h1> Hi! I'm Abhijit Nathwani </h1>
</div>
页面托管在http://abhijitnathwani.github.io
你也可以在我的 GitHub Repo here查看更多源代码
【问题讨论】:
-
标题元素的宽度为 100%,因此光标移动到末尾。例如,如果您将宽度设置为
830px,则光标将停在文本末尾 -
我试过了,它停止了,然后跳到了屏幕的末尾。它没有帮助@Morpheus
-
你试过我的解决方案了吗?
-
现在试用并按要求工作!谢谢@user5014677
标签: html css animation effect typing