首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >多行文本CSS的打字效果

问多行文本CSS的打字效果
EN

Stack Overflow用户
提问于 2020-05-24 19:55:00
回答 1查看 447关注 0票数 0

我正在尝试使用CSS获得打字动画效果。

(参考:https://css-tricks.com/snippets/css/typewriter-effect/)

我正在尝试计算多行文本的效果,想知道如何在键入第二行之前将光标从第一行移走?

代码如下所示。

代码语言:javascript
复制
*{
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    list-style: none;
    text-decoration: none;
  }

.container {
    min-height: 100vh;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

#hero {
    background-image: url(bg.png);
    background-size: cover;
    background-position: top center;
    position: relative;
    z-index: 1;
}
.typewriter h1 {
    color: #fff;
    font-family: monospace;
    overflow: hidden;
    font-size: 80px;
    border-right: .15em solid orange;
    white-space: nowrap;
    margin: 0 auto; /* Gives that scrolling effect as the typing happens */
    /* keeps content in one line */
    letter-spacing: .15em;
    animation: typing 2.5s steps(22, end), blink-caret .75s step-end;
  }
  .typewriter h2 {
    color: #fff;
    font-family: monospace;
    font-size: 40px;
    white-space: nowrap;
    overflow: hidden;
    border-right: .15em solid orange;
    margin: 0 auto; /* Gives that scrolling effect as the typing happens */
    -webkit-animation: typing 2s steps(26, end), blink-caret 1s step-end;
    -webkit-animation-delay: 3s;
    -webkit-animation-fill-mode: both;
    -moz-animation: typing 2s steps(26, end), blink-caret 1s step-end;
    -moz-animation-delay: 3s;
  }

  @keyframes typing {
    from { width: 0 }
  to { width: 100% }
}
  @keyframes blink-caret {
    from, to {
      border-color: transparent
    }
    50% {
      border-color: orange;
    }
  }
代码语言:javascript
复制
  <section id="hero">
    <div class="hero container">
      <div class="typewriter">
        <h1>Hello, <span></span></h1>
        <h2>This is XYZ<span></span></h2>
     </div>
    </div>
  </section>
EN

回答 1

Stack Overflow用户

发布于 2020-05-24 20:11:46

添加动画延迟:在h2上延迟3秒,并在h1中使眨眼-插入符号动画重复4次,不是无限的,它将会工作;)

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

https://stackoverflow.com/questions/61985567

复制
相关文章

相似问题

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