首页 文章

Typed.js文本未显示

提问于
浏览
0

我正在尝试实现Typed.js的新ES6模块版本(不是jQuery版本),但文本不是't appearing - only the cursor (which remains stationary and doesn' t闪烁 . )

我通过NPM安装了没有问题的库,并且正在使用Webpack进行编译 . 当我检查我编译的 app.js 时,该库出现了 . app.js 正在正确加载页面,我在控制台中看不到任何错误 . 只是一个固定的光标,我的动态类型文本应该出现在那里 .

这是我的代码(主要是官方网站上的例子):

typewriter.js

import Typed from 'typed.js';

var typed = new Typed('#typed-text', {
  strings: ["First sentence.", "Second sentence."],
  typeSpeed: 30
});

index.html

<div class="column">
  <p id="typed-text"></p>
</div>

1 回答

  • 0

    Typed.js在 <span> 中呈现您的文本 . 由于您的javascript正在输出 stringstyped-text ,并且由于您希望以段落形式格式化字符串,因此您需要像这样定义 <span>

    index.html

    <div class="column">
    <p>
    <span id="typed-text"></span>
    </p>
    </div>
    

相关问题