18910140161

JavaScript-如何按程序减去文本,然后将所述文本重新填充到一定数量-堆栈溢出

顺晟科技

2022-10-18 12:43:57

68

我有这个脚本,创建一个";类型";实施时的效果。我希望它能够删除句子中的最后一个单词,然后重新输入有生词的那一节。例如,像“这是原始文本”这样的东西然后以同样的方式删除最后4个字母,并将其替换为";这是原始的脚本";,如果这有任何意义的话。

打字机.JS:

var arrText = new Array("This is the original text"); // Array of text to be "typed"
var speed = 80; // Delay speed as text "types" out. Lower value = faster speed
var index = 0; // Start position for the typing effect
var arrLength = arrText[0].length; // Length of the text array

var textPos = 0; // Initialize text position
var contents = ""; // Initialize contents variable

function typewriter() {
  // Aqcuire the destination of the typewriter ID
  var destination = document.getElementById("typewriter");

  // Initiate the innerHTML of the destination, with an initial carat value
  destination.innerHTML =
    contents +
    arrText[index].substring(0, textPos) +
    "<span class='blink'>█<span>";
  // If textPos hasn't reached the array length, increase textPos value
  if (textPos++ != arrLength) {
    setTimeout("typewriter()", speed);
  } else {
    // Subtract text code here???
  }
}

// Wait specified time (in milliseconds) before starting script
setTimeout(typewriter, 500);

.HTML:

<div id="typewriter"></div>

style.CSS

<代码>.闪烁{动画:闪烁动画1400ms步骤(2,开始)无限;-webkit-animation:blink-animation 1400ms步数(2,开始)无限;}@关键帧闪烁动画{向{可见性:隐藏;}}@-webkit-keyframes闪烁动画{向{可见性:隐藏;}}

顺晟科技:

  • TAG:
相关文章
我们已经准备好了,你呢?
2024我们与您携手共赢,为您的企业形象保驾护航