📜  使用 JS 键入文本 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:07.699000             🧑  作者: Mango

代码示例1
document.addEventListener("DOMContentLoaded", function () {
  let letter = 0;
  const text = "Lorem ipsum dolor sit consectetur.";
  function typeText() {
    if (letter < text.length) {
      document.getElementById("type-js").innerHTML += text.charAt(letter);
      letter++;
      let speed = Math.floor(Math.random() * 150) + 50;
      setTimeout(typeText, speed);
    }
  }
  typeText();
});Code language: JavaScript (javascript)