【发布时间】:2017-03-15 22:38:13
【问题描述】:
我需要循环遍历 CSS 打字机效果,并为每个循环更改文本。这是我用于打字机效果的代码。我猜我需要使用 javascript,但我不知道该怎么做。关于如何做到这一点的任何想法?
.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: .15em; /* Adjust as needed */
animation:
typing 3.5s steps(40, end),
blink-caret .75s step-end infinite;
}
body {
background: #333;
color: #fff;
font-family: monospace;
padding-top: 5em;
display: flex;
justify-content: center;
}
/* DEMO-SPECIFIC STYLES */
.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: .15em; /* Adjust as needed */
animation:
typing 3.5s steps(40, end),
blink-caret .75s step-end infinite;
}
/* The typing effect */
@keyframes typing {
from { width: 0 }
to { width: 100% }
}
/* The typewriter cursor effect */
@keyframes blink-caret {
from, to { border-color: transparent }
50% { border-color: blue; }
}
<div class="typewriter">
<h1>The cat and the hat.</h1>
</div>
}
【问题讨论】:
-
请注意:您的代码复制粘贴自:css-tricks.com/snippets/css/typewriter-effect。提及您的来源是一件好事。 :-)
标签: javascript jquery html css effects