首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用css使打字机文本效果循环

问如何使用css使打字机文本效果循环
EN

Stack Overflow用户
提问于 2017-01-24 20:15:02
回答 1查看 2.8K关注 0票数 1

你好我正在尝试用css在我的页面上做一个打字机文本效果,我得到了一个特殊的片段,它给出了一个打字效果,但它确实发送了循环,我需要它循环

这是我使用的初始代码

代码语言:javascript
复制
<div class="typewriter">
  <h1>The cat and the hat.</h1>
</div>

/* 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: orange; }
}

有没有人可以解释一下如何做这个循环,我在网上读到你需要把无穷大的单词加进去,但是我不知道该把这个加在哪里,请帮帮忙。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-01-24 20:19:20

向.typewriter h1添加animation-iteration-count: infinite;将使其循环。

​

代码语言:javascript
复制
/* 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;
  animation-iteration-count: 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: orange;
  }
}
代码语言:javascript
复制
<div class="typewriter">
  <h1>The cat and the hat.</h1>
</div>

​

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41828017

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档