【问题标题】:How to get the cursor to blink upon the completion the second line - Typewriting effect using CSS如何让光标在完成第二行时闪烁 - 使用 CSS 的打字效果
【发布时间】:2020-09-21 02:57:13
【问题描述】:

我正在尝试在网页(黑色背景)的两行上实现打字效果,一旦输入第二个句子,我就无法执行光标闪烁。

我已经发布了 HTML 和 CSS 代码。任何有助于纠正我出错的地方都会有所帮助。

HTML:

      <div class="typewriter">
        <h1>Hi,</h1>
        <h2>This is <span style="color: orange">ABC.</span></h2></div> 

CSS:

.typewriter h1 {
    color: #fff;
    font-family: 'DM Mono', monospace;
    overflow: hidden;
    font-size: 80px;
    border-right: .15em solid black;
    white-space: nowrap;
    letter-spacing: .15em;
    width: 4ch;
    animation: typing 2.5s steps(4, end), blink-caret .75s step-end 4;
  }
.typewriter h2 {
    color: #fff;
    font-family: 'DM Mono', monospace;
    font-size: 40px;
    white-space: nowrap;
    overflow: hidden;
    border-right: .15em solid orange;
    width: 20ch;
    animation: typing2 2s steps(20, end), blink-caret 1s step-end;
    animation-delay: 3s;
    animation-fill-mode: both;
  }
@keyframes typing {
    from { 
        width: 0 
    }
    to { 
      width: 3em;
    }
}
@keyframes typing2 {
    from { 
        width: 0 
    }
    to { 
      width: 20em;
    }
}
@keyframes blink-caret {
    from, to {
      border-color: transparent
    }
    50% {
      border-color: white;
    }
} 

【问题讨论】:

  • 你能再描述一下你的问题吗?
  • 我希望光标在第二行的末尾一直闪烁,而在完成第二行之前它就消失了。
  • 在这里查看第一个示例w3schools.com/cssref/css3_pr_animation.asp。它有无限这个词,也许这有帮助?
  • 动画在这里无限重复,这不是我真正想要的。我只是担心光标的闪烁。这是我提到的链接:css-tricks.com/snippets/css/typewriter-effect)
  • 感谢您的帮助!写完 ABC 后光标消失。我希望它在句号后也继续闪烁。有什么办法可以做到吗?

标签: html css effect


【解决方案1】:

我不知道为什么会这样,但它确实有效。让我知道它是否达到了预期的效果。

    .typewriter h2 {
        color: #fff;
        font-family: 'DM Mono', monospace;
        font-size: 40px;
        white-space: nowrap;
        overflow: hidden;
        border-right: .15em solid orange;
        //this is what i changed
        width: 12ch;
        animation: typing2 2s steps(12, end), blink-caret 1s step-end infinite;
        ////
        animation-delay: 3s;
        animation-fill-mode: both;
    }
    @keyframes typing2 {
        from { 
            width: 0 
        }
        to {
            //this is what i changed
            width: 12ch;
            ////
        }
    }

【讨论】:

  • 对我有用。似乎不能让光标在最后闪烁。在单词“This”之后缺少光标
  • 请立即尝试。
  • 好的,知道了!非常感谢您帮助像我这样的新手。
猜你喜欢
  • 1970-01-01
  • 2021-11-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-07
  • 2022-01-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多